Vulkan

:单件模式:Singleton

#ifndef __SINGLETON_H__
#define __SINGLETON_H__
class Singleton
{
private:
	static Singleton* instance;
	Singleton(){}
public:
	static Singleton* getInstance()
	{
		if (instance == NULL)
		{
			instance = new Singleton();
		}
		return instance;
	}
	~Singleton(){}
	
};
Singleton* Singleton::instance = NULL;
#endif


#include <iostream>
#include "Singleton.h"
using namespace std;
int main()
{
	Singleton *p = Singleton::getInstance();

	return 0;
}


posted on 2015-04-22 19:50  Vulkan  阅读(133)  评论(0编辑  收藏  举报

导航