修复设计模式-单例的一些错误
This commit is contained in:
parent
388564c9d9
commit
b3dd817d4f
@ -114,7 +114,7 @@ private:
|
||||
static singleton *p;
|
||||
static mutex lock_;
|
||||
public:
|
||||
singleton *instance();
|
||||
static singleton *instance();
|
||||
|
||||
// 实现一个内嵌垃圾回收类
|
||||
class CGarbo
|
||||
@ -131,6 +131,7 @@ public:
|
||||
|
||||
singleton *singleton::p = nullptr;
|
||||
singleton::CGarbo Garbo;
|
||||
std::mutex singleton::lock_;
|
||||
|
||||
singleton* singleton::instance() {
|
||||
if (p == nullptr) {
|
||||
|
@ -14,7 +14,7 @@ private:
|
||||
static singleton *p;
|
||||
static mutex lock_;
|
||||
public:
|
||||
singleton *instance();
|
||||
static singleton *instance();
|
||||
|
||||
// 实现一个内嵌垃圾回收类
|
||||
class CGarbo
|
||||
@ -31,6 +31,7 @@ public:
|
||||
|
||||
singleton *singleton::p = nullptr;
|
||||
singleton::CGarbo Garbo;
|
||||
std::mutex singleton::lock_;
|
||||
|
||||
singleton* singleton::instance() {
|
||||
if (p == nullptr) {
|
||||
|
@ -11,12 +11,12 @@ private:
|
||||
static singleton *p;
|
||||
singleton() {}
|
||||
public:
|
||||
singleton *instance();
|
||||
static singleton &instance();
|
||||
};
|
||||
|
||||
singleton *singleton::instance() {
|
||||
singleton &singleton::instance() {
|
||||
static singleton p;
|
||||
return &p;
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user