mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2024-11-29 14:46:02 +08:00
25 lines
546 B
C++
25 lines
546 B
C++
#pragma once
|
|
|
|
/**
|
|
* @brief The Singleton class
|
|
*/
|
|
template<typename T>
|
|
class Singleton {
|
|
public:
|
|
static T *getInstance();
|
|
};
|
|
|
|
template<typename T>
|
|
T *Singleton<T>::getInstance() {
|
|
static T *instance = new T();
|
|
return instance;
|
|
}
|
|
|
|
#define SINGLETON(Class) \
|
|
private: \
|
|
friend class Singleton<Class>; \
|
|
public: \
|
|
static Class* getInstance() { \
|
|
return Singleton<Class>::getInstance(); \
|
|
}
|