FluentUI/example/src/singleton.h
2024-06-28 17:09:23 +08:00

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