I'm trying to use a static variable in my code when trying to use textures, however I keep getting this error:
1>Platform.obj : error LNK2001: unresolved external symbol "private: static unsigned int Platform::tex_plat" (?tex_plat@Platform@@0IA)
I have initialised the variable properly in the cpp file, however I believe this error occurs when trying to access it in another 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: This is where the variable is 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 then wish to use the tex_plat value in this 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 some one explain this error.
add this:
GLuint Platform::tex_plat;
after your class declaration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With