mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2025-01-23 04:14:35 +08:00
26 lines
959 B
C++
26 lines
959 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(); \
|
|
}
|