:单件模式: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;
}
上一篇:ASP.NET中Dataset的table数据合并、数据截取、数据排序


下一篇:8张图理解Java