#include <iostream>
#include <memory>
using namespace std;
class Singleton
{
public:
static Singleton * Instance()
{
if( 0== _instance.get())
{
_instance.reset( new Singleton);
}
return _instance.get();
}
protected:
Singleton(void)
{
cout <<"Create Singleton"<<endl;
}
virtual ~Singleton(void)
{
cout << "Destroy Singleton"<<endl;
}
friend class auto_ptr<Singleton>;
static auto_ptr<Singleton> _instance;
};
//Singleton.cpp
auto_ptr<Singleton> Singleton::_instance(0);
{
return 0;
}
{
protected:
Singleton( void )
{
assert( !ms_Singleton );
}
~Singleton( void )
{
assert( ms_Singleton );
ms_Singleton = 0;
}
static T& getSingleton( void )
{
assert( ms_Singleton );
return ( *ms_Singleton );
}
static T* getSingletonPtr( void )
{
return ms_Singleton;
}
};
{
static ControllerManager& getSingleton(void);
static ControllerManager* getSingletonPtr(void);
};
ControllerManager* ControllerManager::getSingletonPtr(void)
{
return ms_Singleton;
}
ControllerManager& ControllerManager::getSingleton(void)
{
return ( *ms_Singleton );
}