关于C++单例的有关问题
关于C++单例的问题
写了一个单例,总是报无法解析的外部符号的错,求帮助,谢谢!
该怎么改?
我用的是vs2008.
------解决方案--------------------
Singleton* Singleton::m_pInstance = NULL;
------解决方案--------------------
Singleton* Singleton::m_pInstance = NULL;
静态变量要在类外指明赋值!
写了一个单例,总是报无法解析的外部符号的错,求帮助,谢谢!
#include<iostream>
using namespace std;
class Singleton
{
private:
Singleton(){}
static Singleton* m_pInstance;
public:
static Singleton* getInstance()
{
if (m_pInstance == NULL)
m_pInstance = new Singleton();
return m_pInstance;
}
};
int main()
{
Singleton* s1 = Singleton::getInstance();
}
该怎么改?
我用的是vs2008.
------解决方案--------------------
Singleton* Singleton::m_pInstance = NULL;
------解决方案--------------------
Singleton* Singleton::m_pInstance = NULL;
静态变量要在类外指明赋值!