LNK2001 error when accessing static variables C++ -


i'm trying use static variable in code when trying use textures, keep getting error:

1>platform.obj : error lnk2001: unresolved external symbol "private: static unsigned int platform::tex_plat" (?tex_plat@platform@@0ia) 

i have initialised variable in cpp file, believe error occurs when trying access in method.

.h

class platform : public object {     public:         platform(void);         ~platform(void);         platform(glfloat xcoordin, glfloat ycoordin, glfloat widthin);         void draw();         static int loadtexture();      private:         static gluint tex_plat; }; 

.cpp classes: variable initialised

int platform::loadtexture(){  gluint tex_plat = soil_load_ogl_texture(             "platform.png",             soil_load_auto,             soil_create_new_id,             soil_flag_invert_y             );      if( tex_plat > 0 )     {         glenable( gl_texture_2d );         return tex_plat;     }     else{         return 0;     } } 

i wish use tex_plat value in method:

void platform::draw(){     glbindtexture( gl_texture_2d, tex_plat );     glcolor3f(1.0,1.0,1.0);     glbegin(gl_polygon);     glvertex2f(xcoord,ycoord+1);//top left     glvertex2f(xcoord+width,ycoord+1);//top right     glvertex2f(xcoord+width,ycoord);//bottom right     glvertex2f(xcoord,ycoord);//bottom left     glend(); } 

could 1 explain error.

static member must defined outside class body, have add definition , provide initializer there:

class platform : public object {     public:         platform(void);         ~platform(void);         platform(glfloat xcoordin, glfloat ycoordin, glfloat widthin);         void draw();         static int loadtexture();      private:         static gluint tex_plat; };  // in source file gluint platform::tex_plat=0; //initialization 

it possible initialize inside class but:

to use in-class initialization syntax, constant must static const of integral or enumeration type initialized constant expression.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -