C++单例

 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;

 

posted @ 2018-01-26 11:03  bingo_qiu  阅读(178)  评论(1)    收藏  举报