blob: f864a42b6a835536c3097e1a37f744cfdece772d (
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
|
#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;
#endif
|