yhkylin-backup-tools/common/singleton.h

36 lines
828 B
C
Raw Normal View History

2021-08-06 10:20:03 +08:00
/**
* brief 1.使
* 2.Singleton模板的默认构造函数是受保护的protected
* 3.token类型的参数
* author
* note 使
class MysqlPool :public Singleton<MysqlPool> {
public:
MysqlPool(token) {};
~MysqlPool();
...
};
*/
#ifndef SINGLETON_H_
#define SINGLETON_H_
template <class T>
class Singleton
{
public:
Singleton(const Singleton&) = delete;
Singleton& operator= (const Singleton) = delete;
public:
2023-03-17 17:59:26 +08:00
static T& instance() {
2021-08-06 10:20:03 +08:00
static T _{ token{} };
return _;
}
protected:
struct token {};
Singleton() = default;
};
#endif