Skip to main content
gamedev.net
🔒 Locked

STL map issue

Started by chikinpotpi Mar 28, 2009 at 4:13 PM 1 replies 600+ views
Original Post
chikinpotpi
chikinpotpi
I am a C# .NET programmer who has recently switched to c++, and thus my understanding on some things could be a little fuzzy... i am attempting to create a static STL map for the purpose of keeping track of which textures i have already loaded into video memory. It needs to store a string, and a GLuint, and after reading some things i managed to get that working, but when i tried to make it a static member of my texture loading class, everything goes haywire... so here is my code, and my error, any help would be greatly appreciated... Header: #ifndef __TEXTURELOADER_H__ #define __TEXTURELOADER_H__ #include #include #include #include #include #include #include #include "TGAHeader.h" #include "Texture.h" #include "TGA.h" class TextureLoader { private: static bool LoadTGA(Texture * texture, const char * filename); static bool LoadUncompressedTGA(Texture *, const char * filename, FILE *); static bool LoadCompressedTGA(Texture *, const char * filename, FILE *); static std::map textures; public: static GLuint LoadTexture(std::string filename); }; #endif code for LoadTexture (this is where the error occurs i think) : GLuint TextureLoader::LoadTexture(std::string filename) { Texture tex; //create Texture structure to load into GLuint texID; //greate ID for texture once loaded in OpenGL if(textures.find(filename) != textures.end()) { return textures.find(filename)->second; } if(LoadTGA(&tex, filename.c_str())) //Try to load texture from file, if sccuessful, load into OpenGl { glGenTextures(1, &texID); glBindTexture(GL_TEXTURE_2D, texID); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 4, tex.width, tex.height, 0, tex.type, GL_UNSIGNED_BYTE, tex.imageData); } free(tex.imageData); textures[filename] = texID; return texID; //return OpenGl Texture ID so that we can use it } All the code compiles fine, and the application launches, but then i get this: ZeroLink: unknown symbol '__ZN13TextureLoader8texturesE' SimpleGame has exited due to signal 6 (SIGABRT). Again, my "c++-fu" is very weak so this could be something very simple... Thanks for taking the time to read!!
Antheus
Antheus
When a static member is declared, it's shared by all instances. It's up to you to specify where it's allocated.
static std::map<std::string, GLuint> textures; 
means simply that there exists textures member, but it doesn't say where. That's up to linker to determine.

So somewhere (usually in accompanying cpp file), such member is defined.
Basically:
std::map<std::string, GLuint> TextureLoader::textures;


Also [ source ] or [ code ] tags make things more readable.
chikinpotpi
chikinpotpi
Thanks for the reply!!

That was spot on and very insightful!

Its amazing the things you don't learn when Visual Studio writes half your code for you...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.