LNK2001 Fehler beim Zugriff auf statische Variablen C ++
Ich versuche, eine statische Variable in meinem Code zu verwenden, wenn ich versuche, Texturen zu verwenden. Ich erhalte jedoch weiterhin den folgenden Fehler:
1>Platform.obj : error LNK2001: unresolved external symbol "private: static unsigned int Platform::tex_plat" (?tex_plat@Platform@@0IA)
Ich habe die Variable in der cpp-Datei richtig initialisiert, glaube jedoch, dass dieser Fehler auftritt, wenn ich versuche, auf sie mit einer anderen Methode zuzugreifen.
.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-Klassen: Hier wird die Variable initialisiert
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;
}
}
Ich möchte dann den Wert tex_plat in dieser Methode verwenden:
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();
}
könnte jemand diesen fehler erklären.