设计模式单件实现C++

/*********************************
*设计模式--单件实现
*C++语言
*Author:WangYong
*Blog:http://www.cnblogs.com/newwy
********************************/
#include <iostream>
using namespace std;

class Singleton
{
public:
	static Singleton * Instance()
	{
		if(_instance == 0)
			_instance = new Singleton();
		return _instance;
	}
protected :
	Singleton () {cout<<"Singleton ....";}
private:
	static Singleton * _instance;
};
Singleton* Singleton::_instance = 0;

int main()
{
	Singleton *sgn = Singleton::Instance();
	return 0;
}


原文地址:https://www.cnblogs.com/newwy/p/1855204.html