在写C++的单例模式的时候链接器报错:无法解析的外部符号。我以为是我的单例模式写错了,在网上复制了一个单例模式的例子,结果还是报一样的错。代码如下:
class CSingleton
{
public:
static CSingleton* GetInstance()
{
if (m_pInstance == NULL)
m_pInstance = new CSingleton();
return m_pInstance;
}
private:
CSingleton() {};
static CSingleton * m_pInstance;
};
int main() {
CSingleton* r = CSingleton::GetInstance();
std::cout << "r";
}
会在static CSingleton * m_pInstance;这里报错