自从我用C++编程以来已经有一段时间了.我试图实现一个单例类,但我得到一个未解析的外部符号.你们能指出解决这个问题吗?提前致谢!
class Singleton
{
Singleton(){}
Singleton(const Singleton & o){}
static Singleton * theInstance;
public:
static Singleton getInstance()
{
if(!theInstance)
Singleton::theInstance = new Singleton();
return * theInstance;
}
};
Run Code Online (Sandbox Code Playgroud)
错误:
错误3错误LNK1120:1个未解析的外部
错误2错误LNK2001:未解析的外部符号
"private: static class Singleton * Singleton::theInstance" (?theInstance@Singleton@@0PAV1@A)