标签:
<pre name="code" class="cpp">/*Singleton.h*/
#ifndef SINGLETON_H
#define SINGLETON_H
class Singleton
{
public:
static Singleton *Instance();
protected:
Singleton();
private:
static Singleton *instance_;
};
#endif<pre name="code" class="cpp">/*Singleton.cpp*/
#include "Singleton.h"
#include <iostream>
Singleton *Singleton::instance_=0;
Singleton::Singleton()
{
std::cout<<"Singleton..."<<std::endl;
}
Singleton *Singleton::Instance()
{
if(instance_==0)
{
instance_=new Singleton();
}
return instance_;
}/*main.cpp*/
#include "Singleton.h"
int main()
{
Singleton *sgn=Singleton::Instance();
return 0;
}
标签:
原文地址:http://blog.csdn.net/tlzhatao/article/details/45458027