/*Singleton.h*/
#ifndef SINGLETON_H
#define SINGLETON_H
class Singleton
{
public:
static Singleton *Instance();
protected:
Singleton();
private:
static Singleton *instance_;
};
#endif
/*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;
}