C++简单单例模式

 1 #ifndef _SINGLETON_H_
 2 #define _SINGLETON_H_
 3 #include <stdio.h>
 4 
 5 template<typename T>
 6 class CSingleton
 7 {
 8 private:
 9     CSingleton(){}   //构造函数是私有的
10 public:
11     static T * GetInstance()
12     {
13         static T instance;   //局部静态变量
14         return &instance;
15     }
16 };
17 
18 #endif
原文地址:https://www.cnblogs.com/tangxin-blog/p/4722250.html