单例
1.饿汉式
class singleton { protected: singleton(){} private: static singleton* p; public: static singleton* getInstance(); static void destory() { if(p) delete p; } private: ~singleton(){} }; singleton* singleton::p = new singleton;//new后面加括号调用无参构造函数,加括号的调用默认的或唯一的构造函数。 singleton* singleton::getInstance() { return p; }