Student.h
1:
#ifndef __SINGLETON_H__
#define __SINGLETON_H__
4:
#include <memory>
6:
class T>
class SingleT
9: {
public:
static T * Instance()
12: {
if (!p)
14: {
new T;
16: }
17:
return p;
19: }
20:
void Create()
22: {
if (!p)
24: {
new T;
26: }
27: }
28:
void Destroy()
30: {
if (p)
32: {
delete p;
34: p = NULL;
35: }
36: }
37:
static T * Get()
39: {
return p;
41: }
42:
void Reset()
44: {
45: Destroy();
46: Create();
47: }
48:
protected:
static T * p;
51: };
52:
class T>
54: T * SingleT<T>::p = NULL;
55:
#endif
57: