单例模式
caven 2006-02-27 08:05:24 class Singleton
{
public:
static Singleton * Instance()
{
if( 0== _instance)
{
_instance = new Singleton;
}
return _instance;
};
void method1()
{
};
protected:
Singleton(void)
{
}
virtual ~Singleton(void)
{
}
static Singleton* _instance;
};
int main(int argc, char* argv[])
{
Singleton::Instance()->method1();
return 0;
}
提示:
P1.obj : error LNK2001: unresolved external symbol "protected: static class Singleton * Singleton::_instance" (?_instance@Singleton@@1PAV1@A)
Debug/P1.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
为什么?