1 Star 0 Fork 0

吕冬/resource-manager

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
singleton.h 618 Bytes
一键复制 编辑 原始数据 按行查看 历史
#ifndef SINGLETON_H
#define SINGLETON_H
#include <mutex>
template<typename T>
class Singleton{
public:
static T* instance()
{
if (s_pInstance == nullptr)
{
std::lock_guard<std::mutex> mtx(s_mtxInstance);
if (s_pInstance == nullptr)
{
s_pInstance = new T;
}
}
return s_pInstance;
}
private:
static T* s_pInstance;
static std::mutex s_mtxInstance;
};
template<typename T>
T* Singleton<T>::s_pInstance = nullptr;
template<typename T>
std::mutex Singleton<T>::s_mtxInstance;
#endif // SINGLETON_H
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/flvd/resource-manager.git
git@gitee.com:flvd/resource-manager.git
flvd
resource-manager
resource-manager
master

搜索帮助