//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>
using namespace std;
Singleton::Singleton()
{
cout << "Singleton.." << endl;
}
Static * Singleton::Instance()
{
if (_instance == 0)
{
_instance = new Singleton();
}
return _instance;
}
Singleton * Singleton::_instance = 0;
//main.cpp
#include "Singleton.h"
using namespace std;
void main(int argc, char * argv[])
{
Singleton * sgt = Singleton::Instance();
return 0;
}