标签:
直接上代码:
class CMyClass { public: CMyClass(void); ~CMyClass(void); public: static CMyClass* GetInstance(); private: static CMyClass* m_pMyClass; };
#include "MyClass.h" CMyClass* CMyClass::m_pMyClass = NULL; CMyClass::CMyClass(void) { } CMyClass::~CMyClass(void) { if (NULL != m_pMyClass) { delete m_pMyClass; m_pMyClass = NULL; } } CMyClass* CMyClass::GetInstance() { if (NULL == m_pMyClass) { m_pMyClass = new CMyClass(); } return m_pMyClass; }
答案参考:http://blog.csdn.net/yong199105140/article/details/8425781
标签:
原文地址:http://www.cnblogs.com/whl2012/p/4830885.html