blob: 65c9e60ff68f62b66d711ba6253e6acadf6c5dc3 (
plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#ifndef SINGLETON_H
#define SINGLETON_H
template<class T>
class Singleton
{
public:
static T* Instance()
{
if (!instance) instance = new T;
return instance;
}
static void Destroy()
{
delete instance;
instance = nullptr;
}
protected:
Singleton()
{
instance = static_cast<T*>(this);
};
virtual ~Singleton() {};
static T* instance;
private:
Singleton(const Singleton& singleton);
Singleton& operator = (const Singleton& singleton);
};
template<class T>
T* Singleton<T>::instance = nullptr;
#define Get(T) T::Instance()
#endif
|