Skip to content

Commit 8daa2ba

Browse files
L-SuperLight-City
authored andcommitted
fix: 单例模式静态局部变量代码缺陷
《Effective C++》中Singleton写法是reference-returning,非pointer-returning
1 parent 077cec7 commit 8daa2ba

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

design_pattern/singleton/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,9 @@ singleton *singleton::instance() {
219219
Scott Meyer在《Effective C++》中提出了一种简洁的singleton写法
220220
221221
```cpp
222-
singleton *singleton::instance() {
222+
singleton &singleton::instance() {
223223
static singleton p;
224-
return &p;
224+
return p;
225225
}
226226
```
227227

0 commit comments

Comments
 (0)