• Advertisement
Sign in to follow this  

Singleton Linking Error

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello im trying to make a sinple singleton class everything compiles but i get a linking error error LNK2001: unresolved external symbol "private: static class SoundManager * SoundManager::instance" (?instance@SoundManager@@0PAV1@A) im not doing anything special with the code...jsut has a getSingleton method which returns the instace of the class class SoundManager { public: static SoundManager* getSingletonPtr() { if(instance == 0) instance = new SoundManager(); return instance; } protected: SoundManager() { } ~SoundManager() { } private: static SoundManager* instance; }; and to call it im just using SoundManager::getSingleton(); can someone explain why im geting that linking error im compiling using visual studios 2003 and running on win xp thanks

Share this post


Link to post
Share on other sites
Advertisement
When you declare a static variable in a class, you still need to define it in one source file. So in your case, in one source file, at namespace scope (not inside a class definition or another function) you should put:

SoundManager* SoundManager::instance = 0;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement