forked from coologic/CppDesignPattern
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsigleton.h
More file actions
40 lines (40 loc) · 941 Bytes
/
sigleton.h
File metadata and controls
40 lines (40 loc) · 941 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
32
33
34
35
36
37
38
39
40
#ifndef SIGLETON_H
#define SIGLETON_H
/**
* @brief 非线程安全单例,无多线程时使用
*/
class Singleton {
public:
/**
* @brief 单例模式,获取实例化对象
* @param 无
* @return 单例对象
*/
static Singleton *GetInstance();
/**
* @brief 单例模式,主动销毁实例化对象
* @param 无
* @return 无
*/
static void DestoryInstance();
private:
/**
* @brief 构造函数
*/
Singleton();
/**
* @brief 单例模式在程序结束时自动删除单例的方法
*/
class SingletonDel {
public:
~SingletonDel() {
if (m_instance != nullptr) {
delete m_instance;
m_instance = nullptr;
}
}
};
static SingletonDel m_singleton_del;///程序结束时销毁
static Singleton *m_instance; //单例对象指针
};
#endif // SIGLETON_H