首页 > 其他 > 详细

单例类

时间:2015-04-14 17:59:53      阅读:141      评论:0      收藏:0      [点我收藏+]
#include <stdio.h>
#include <stdlib.h>

class Singleton
{
       Singleton(void ){}//构造函数为私有的
       static Singleton *pSingleton;
public:
       static Singleton * CreateSingleton()
      {
             if(pSingleton ==NULL)
            {
                   pSingleton = new Singleton;
            }
             return pSingleton ;
      }
       void Output ()
      {
             printf("asdasdasd\n" );
      }

};
Singleton* Singleton ::pSingleton  NULL; //必须初始化

void main ()
{
       Singleton::CreateSingleton ()->Output();
       Singleton::CreateSingleton ()->Output();
       getchar();
       return;
}

单例类

原文:http://blog.csdn.net/u012454516/article/details/45045759

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!