C++之单例模式代码实现
来源:互联网 发布:网络信息安全重大事件 编辑:程序博客网 时间:2024/05/17 22:12
template <typename Type>
class Singleton
{
public:
static Type* getInstance()
{
if (!_instance)
{
unique_lock<mutex> lock(_mutex);
if (!_instance)
_instance = make_unique<Type>();
}
return _instance.get();
}
class Singleton
{
public:
static Type* getInstance()
{
if (!_instance)
{
unique_lock<mutex> lock(_mutex);
if (!_instance)
_instance = make_unique<Type>();
}
return _instance.get();
}
private:
static unique_ptr<Type> _instance;
static mutex _mutex;
};
static unique_ptr<Type> _instance;
static mutex _mutex;
};
#define IMPLEMENT_SINGLETON(Type) \
unique_ptr<Type> Singleton<Type>::_instance; \
mutex Singleton<Type>::_mutex;
unique_ptr<Type> Singleton<Type>::_instance; \
mutex Singleton<Type>::_mutex;
阅读全文
0 0
- 单例模式代码实现(C++)
- C++之单例模式代码实现
- 【C++】单例模式之C++实现
- 设计模式之单例模式(C++代码实现)
- 单例模式之静态代码块实现
- objective-C之宏定义实现单例设计模式
- 设计模式之单例模式(代码)
- 设计模式--单例模式 C++实现
- C++--模式之单例模式
- (C#)设计模式 之 单例模式
- 设计模式之单例模式(C++)
- C#--设计模式之单例模式
- 单例模式的简单代码实现
- 单例模式代码实现与解析
- 单例设计模式的实现代码
- 单例模式及C++实现代码
- 单例模式(Java代码实现)
- 单例模式及C++实现代码
- 【漏洞分析】Discuz X3.3补丁安全分析
- Mysql编码问题总结
- HDU2490 Parade 单调队列优化DP
- JavaWeb-权限管理
- 最短路专题
- C++之单例模式代码实现
- [ ArcGIS for Server 10.1 系列 ]
- 转载的psql基础知识
- 1002:一元二次方程
- redis3.0.0配置文件详解
- opencl 返回值
- 学习 R 语言词云wordcloud--笔记
- Android设计模式之(11)----观察者模式
- 有关boost库的简要说明