C++ Singleton undefined reference to
问题 I am new to C++ and trying to understand the Singleton Pattern in C++. myclass.h #ifndef MYCLASS_H #define MYCLASS_H class Myclass { public: static Myclass* getInstance(); private: Myclass(){} Myclass(Myclass const&){} Myclass& operator=(Myclass const&){} static Myclass* m_instance; }; #endif // MYCLASS_H myclass.cpp #include "myclass.h" Myclass* Myclass::getInstance() { if (!m_instance) { m_instance = new Myclass; } return m_instance; } The compiler can't compile. I get the following error,