forked from zhuzichu520/FluentUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
singleton.h
26 lines (22 loc) · 960 Bytes
/
singleton.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#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(); \
}