c++单例模式

上一篇 / 下一篇  2015-09-25 17:30:58 / 个人分类:c++

// 111.cpp : 定义控制台应用程序的入口点。
//单例模式

#include "stdafx.h"
#include <iostream>
using namespace std;

class father
{
public:

static father* GetInistance(){
if (instance == NULL)
{
instance = new father();
}
return instance;

protected:

static  father* instance ;
father(){}
father(const father&){}
};

father* father::instance = NULL; //静态成员变量使用之前必须先定义赋初始值


int _tmain(int argc, _TCHAR* argv[])
{



father *p = father::GetInistance();

return 0;
}

http://www.jellythink.com/archives/82
http://www.cnblogs.com/SelaSelah/archive/2012/04/09/2438651.html


TAG:

 

评分:0

我来说两句

Open Toolbar