Singleton Linking Error

Started by
2 comments, last by StoneDevil 18 years, 4 months ago
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
Advertisement
look here
http://www.gamedev.net/reference/articles/article1439.asp
-----"Master! Apprentice! Heartborne, 7th Seeker Warrior! Disciple! In me the Wishmaster..." Wishmaster - Nightwish
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;
thanks guys thats what the problem was....

This topic is closed to new replies.

Advertisement