book: fix incorrect return value description of std::weak_ptr expired (#144)

* Fix error

资源尚存在时,`std::weak_ptr` 的 `expired()` 方法返回 `false`, 否则返回 `true`。

* book: fix error

Fix error, while the resource of `std::shared_ptr` exists, `std::weak_ptr`'s `expired()` method returns `false`, otherwise it returns `true`.
This commit is contained in:
Tengfei Niu
2020-11-17 15:34:05 +08:00
committed by GitHub
parent 56de7fa327
commit 1e78a01ac0
2 changed files with 3 additions and 3 deletions

View File

@@ -187,7 +187,7 @@ The solution to this problem is to use the weak reference pointer `std::weak_ptr
In the above figure, only B is left in the last step, and B does not have any smart pointers to reference it, so this memory resource will also be released.
`std::weak_ptr` has no `*` operator and `->` operator, so it can't operate on resources. Its only function is to check if `std::shared_ptr` exists, its `expired() The ` method can return `true` when the resource is not released, otherwise it returns `false`.
`std::weak_ptr` has no `*` operator and `->` operator, so it can't operate on resources. Its only function is to check if `std::shared_ptr` exists, its `expired()` method can return `false` when the resource is not released, otherwise it returns `true`.
## Conclusion
@@ -201,4 +201,4 @@ The technology of smart pointers is not novel. It is a common technology in many
## Licenses
<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-nd/4.0/88x31.png" /></a><br />This work was written by [Ou Changkun](https://changkun.de) and licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/4.0/">Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License</a>. The code of this repository is open sourced under the [MIT license](../../LICENSE).
<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-nd/4.0/88x31.png" /></a><br />This work was written by [Ou Changkun](https://changkun.de) and licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/4.0/">Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License</a>. The code of this repository is open sourced under the [MIT license](../../LICENSE).