首页 > 其他 > 详细

单例模式实例

时间:2014-09-01 17:48:23      阅读:128      评论:0      收藏:0      [点我收藏+]
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;

class CSingleton
{
private:
	CSingleton()   //构造函数是私有的
	{
	}
	static CSingleton *m_pInstance;
public:
	static CSingleton * GetInstance()
	{
		if(m_pInstance == NULL)  //判断是否第一次调用
			m_pInstance = new CSingleton();
		return m_pInstance;
	}
};

CSingleton* CSingleton::m_pInstance=NULL;

int main()
{	
	CSingleton* s1=CSingleton::GetInstance();


	system("pause");
	return 0;
}

单例模式实例

原文:http://blog.csdn.net/cjc211322/article/details/38981821

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