懒汉模式
class singleton{ private: singleton(){}; static singleton* m_instance; singleton(const singleton&)=delete; singleton& operator=(singleton&)=delete; public: static singleton* getInstance(); ~singleton(){}; }; singleton* singleton::m_instance = nullptr; singleton* singleton::getInstance(){ if (m_instance == nullptr) { lock; if (m_instance == nullptr) { m_instance = new singleton(); } unlock; } return m_instance; }