c++实现单例模式

来源:互联网 发布:厦门优化公司 编辑:程序博客网 时间:2024/05/18 17:57
class CSystem{private:CSystem(void);//1、私有构造函数public:static Object& getInstance();//2、静态方法void destroy();~CSystem(void);};Object& CSystem::getInstance(){static Object obj = new Object();//3、静态对象return obj;}void CSystem::destroy(){delete obj;}int main(){Object obj = CSystem::getInstance();/*....code....*/return 0;}

0 0
原创粉丝点击