该模式很简单,仅列举下列的代码:
class SingleTonClass
{
private:
static SingleTonClass* singleton;
private:
SingleTonClass()
{}
public:
static SingleTonClass* GetInstance();
};
SingleTonClass::singleton = NULL;
SingleTonClass * SingleTonClass::GetInstance()
{
if(singleton == NULL)
singleton = new SingleTonClass();
return singleton;
}