Files
ylib/include/base/singleton.hpp
2024-06-03 19:09:35 +08:00

31 lines
576 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
#include <string>
#include <iostream>
/**
* 基础错误类
*/
namespace ylib
{
// 单例基类模板
template <typename T>
class singleton {
public:
// 获取单例对象的静态方法
static T* getInstance() {
static T instance; // C++11以后局部静态变量的初始化是线程安全的
return &instance;
}
protected:
// 禁止拷贝构造函数和拷贝赋值操作
//singleton(const singleton&) = delete;
//singleton& operator=(const singleton&) = delete;
// 允许析构
//virtual ~singleton() = default;
};
}