[go: up one dir, main page]

Menu

[r3]: / trunk / singleton.h  Maximize  Restore  History

Download this file

33 lines (25 with data), 494 Bytes

 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
#ifndef _SINGLETON_H
#define _SINGLETON_H
#endif
#ifndef _ASSERT_H
#include <cassert>
#endif
template <class T>
class Singleton {
private:
Singleton(Singleton const&);
Singleton& operator = (Singleton const&);
static T* m_pInstance;
protected:
Singleton();
~Singleton();
public:
static T* Instance() {
if(!m_pInstance) {
m_pInstance = new T;
}
assert(m_pInstance != NULL);
return m_pInstance;
}
};
template <class T> T* Singleton<T>::m_pInstance = NULL;