FluentUI/example/src/singleton.h
朱子楚\zhuzi 44f7948df3 update
2024-04-12 16:50:49 +08:00

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