Error LNK2001 无法解析的外部符号 的几种情况及解决办法

xiaoxiao2021-02-28  34

Error LNK2001 无法解析的外部符号 的几种情况及解决办法

多线程下的单例模式

        这里要处理的是懒汉模式。

[cpp]  view plain  copy   class Singleton  {  private:      static Singleton* m_instance;      Singleton(){}  public:      static Singleton* getInstance();  };    Singleton* Singleton::getInstance()  {      if(NULL == m_instance)      {        m_instance = new Singleton;     }      return m_instance;  }  

Error LNK2001 无法解析的外部符号 

解决方法:

static Singleton* m_instance;移动到类的头文件中类定义尾部。

转载请注明原文地址: https://www.6miu.com/read-1700201.html

最新回复(0)