FluentUI/example/src/singleton.h
朱子楚\zhuzi 44acdbcf7f update
2024-04-11 20:29:59 +08:00

25 lines
594 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(); \
} \