C++单例

2018-01-26 11:38:07来源:cnblogs.com作者:bingo_qiu人点击

分享
 1 template<class T> 2 class Singleton 3 { 4 public: 5     using object_type = T; 6     struct object_creator 7     { 8         object_creator() 9         {10             Singleton<T>::instance();11         }12     };13  14     static object_creator creator_object;15 public:16     static object_type* instance()17     {18         static object_type _instance;19         return(&_instance);20     }21 };22 template<typename T> typename Singleton<T>::object_creator Singleton<T>::creator_object;

最新文章

123

最新摄影

闪念基因

微信扫一扫

第七城市微信公众平台