采用C++实现单例模式
class Singleton // 这是两种方式 { private: static Singleton single; Singleton(){} Singleton &operator=(Singleton & s)// 屏蔽拷贝构造函数和赋值操作符 { } Singleton(const Singleton &s){} public: int m_value; static Singleton * getInstance() { return &single; } }; Singleton Singleton::single; class CSingleton { private: CSingleton() //构造函数是私有的 { } CSingleton(const CSingleton &); CSingleton & operator = (const CSingleton &); public: static CSingleton & GetInstance() { static CSingleton instance; //局部静态变量 return instance; } };