//懒汉式单例类 class singleton { public: static singleton *getInstance() { if(instance==NULL) instance=new singleton(); return instance; } private: static singleton*instance; singleton(){} int count=1; }; singleton * singleton::intstace=NULL; //饿汉子单例 class singleton { public: static singleton*getInstance() { return instance; } private: static singleton*instance; int count=1; singleton(){} }; //每次直接实例化instnce,get方法直接返回这个实例 singleton * singleton:instance=new singleton();