Singleton Linking Error
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
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;
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement