View Code
#include <stdio.h>
class Singleton
{
public:
static Singleton* Intance()
{
if(!mSingleTon)
mSingleTon=new Singleton();
return mSingleTon;
}
protected:
Singleton()
{
printf("object init");
}
private:
static Singleton* mSingleTon;
};
Singleton* Singleton::mSingleTon=NULL;
int main()
{
Singleton *sgn = Singleton::Intance();
Singleton *sgn2=Singleton::Intance();
return 0;
}