yhkylin-backup-tools/common/singleton.h

36 lines
824 B
C
Raw Permalink Normal View History

2022-11-01 10:40:05 +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:
static T& inst() {
static T _{ token{} };
return _;
}
protected:
struct token {};
Singleton() = default;
};
#endif