A singleton is a very basic concept really.
You can use lazy instantiation, or controlled. Lazy is fine if it does not matter who/what creates the singleton first, but is not ok if the creation time matters(rare case IMO).
This is a basic class using lazy instantiation.(not tested so may have syntax error)
Code:
class MySingleton
{
private:
MySingleton() {};
~MySingleton() {};
static MySingleton* m_Singleton;
public:
static MySingleton* Get()
{
if ( !m_Singleton )
m_Singleton = new MySingleton();
return m_Singleton;
}
static void Release()
{
if ( m_Singleton )
{
delete m_Singleton;
m_Singleton = 0;
}
}
};
//To use it
MySingleton* Test = MySingleton::Get();
//Don't forget to release it when your done
MySingleton::Release();
The other way is pretty simple to figure out.