#include<iostream>
using namespace std;
class Singleton
{
private:
Singleton(){ cout << "singleton construct" << endl; }
static Singleton* _instance;
class Cleaner
{
public:
Cleaner(){ cout << "cleaner construct" << endl; }
~Cleaner()
{
if (Singleton::_instance)
delete Singleton::_instance;
cout << "cleaner deconstruct" << endl;
cout << "singleton deconstruct" << endl;
}
};
public:
static Singleton* Instance()
{
if (_instance == NULL)
{
_instance = new Singleton();
static Cleaner cl;
}
return _instance;
}
};
Singleton* Singleton::_instance = NULL;
int main()
{
Singleton *s1 = Singleton::Instance();
Singleton *s2 = s1;
return 0;
}