#ifndef SINGLETON_H #define SINGLETON_H class CSingleton { private: CSingleton() //构造函数是私有的 { } static CSingleton *m_pInstance; public: static CSingleton * GetInstance() { if(m_pInstance == NULL) //判断是否第一次调用 m_pInstance = new CSingleton(); return m_pInstance; } charstr[32];//属性 }; CSingleton* CSingleton::m_pInstance=NULL;//这句必须加,一般来说,要加在cpp文件中。不然会出现“unresolved external symbol”的错误。 #endif
|
|