class SingleTonDemo { private: static SingleTonDemo *pInstance; SingleTonDemo(){ if (!pInstance) { pInstance = new SingleTonDemo(); } } ~SingleTonDemo(){ print("Destructor Invoked"); } public: static SingleTonDemo* getInstace(){ if (!pInstance) { pInstance = new SingleTonDemo(); } return pInstance; } static void Destroy(SingleTonDemo* pInstance){ if (pInstance) { delete pInstance; pInstance = NULL; } } void SayHello(){ print("Hello~"); } }; void main(){ SingleTonDemo *demo = SingleTonDemo::getInstace(); }
第一次发帖子,有什么不对的还请多包涵(*^__^*) 嘻嘻……
解决方案
40
SingleTonDemo 的构造函数里面又在调用 SingleTonDemo 的构造函数, 死循环