/********************************* *设计模式--单件实现 *C++语言 *Author:WangYong *Blog:http://www.cnblogs.com/newwy ********************************/ #include <iostream> using namespace std; class Singleton { public: static Singleton * Instance() { if(_instance == 0) _instance = new Singleton(); return _instance; } protected : Singleton () {cout<<"Singleton ....";} private: static Singleton * _instance; }; Singleton* Singleton::_instance = 0; int main() { Singleton *sgn = Singleton::Instance(); return 0; }