需求:
- 线程安全:(C++11标准保证局部静态变量的初始化是线程安全的)
- 代码简单
- 懒加载
- 程序结束自动释放
template <typename T>
class Single {
public:
Single(const Single<T>& instance) = delete;
Single operator=(const Single<T>& instance) = delete;
T &getInstance(){
static T instance;
return instance;
}
protected:
Single() = default;
virtual ~Single() = default;
};