C++单例
template<typename T> class Singleton { public: static T& GetInstance() { static T instance; return instance; } virtual ~Singleton() { } Singleton(const Singleton&) = delete; Singleton& operator =(const Singleton&) = delete; protected: Singleton() { } };
用法
class Config : public Singleton<Config> { friend class Singleton<Config>; public: Config(); ~Config(); };