This topic is 3450 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

hello, I have this problem. I declare a class in a header like this #ifndef HE_TEXTURE_MANAGER #define HE_TEXTURE_MANAGER class CTextureManager { ... }; #endif my project builds fine, but when I try to create an instance of this class in the header this way: #ifndef HE_TEXTURE_MANAGER #define HE_TEXTURE_MANAGER class CTextureManager { ... } sTextureManager; #endif I get a linker eror in all .obj files that include this header, the error is : Linking... 1>Texture.obj : error LNK2005: "class CTextureManager sTextureManager" (?sTextureManager@@3VCTextureManager@@A) already defined in Mesh.obj 1>TextureManager.obj : error LNK2005: "class CTextureManager sTextureManager" (?sTextureManager@@3VCTextureManager@@A) already defined in Mesh.obj I include the header in mesh.cpp, texture.cpp and texturemanager.cpp. Why can't I have instance of this class in header it is declared in?

Share on other sites
Global variables can't be defined in headers. You can declare the global in the header as extern and then define it in a source file.
// in the headerextern CTextureManager sTextureManager;// in one source fileCTextureManager sTextureManager;

Share on other sites
THANKS! That does it

• 17
• 11
• 15
• 9
• 49
• Forum Statistics

• Total Topics
631393
• Total Posts
2999765
×