Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Learning C++ const reference

Name: Anonymous 2011-12-10 11:09

Hi, guys... I'm trying to learn C++ and OpenGL...

I want to return the first pointer of the array... but maintaing the const correctness...


it happened that:

class Foo{
private:
    GLint array[64][64][4];
public:
    const GLint& get_array(){return array;}
}


gives me this compiler error:


/Users/Pella/Desktop/c/OpenGL_Nehe_cpp/CheckImag.h:28:0 /Users/Pella/Desktop/c/OpenGL_Nehe_cpp/CheckImag.h:28: error: invalid initialization of reference of type 'const GLubyte&' from expression of type 'GLubyte (*)[64][4]'



can you help me out in understanding the const correctness?

Name: Anonymous 2011-12-10 14:01

>>5

Have StackOverflow suggested that to you? No wonder that place is a crap.

First, avoid C-style casts. They can always be replaced by proper cast operators, in any situation. You'll be using static_cast. If you're forced to use reinterpret_cast or const_cast, it's a very strong sign you're doing something wrong.

Second, study a bit further the difference between a pointer and a reference. They have different syntax, and are intended to be used in different situations, albeit in the lower level they're implemented likewise. You want a pointer to the last array dimension, is that so? Your question is unclear.

Third, const correctness has seemingly nothing to do with your problem. You're having problems with the return type.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List