From 1e78a01ac0ff912b323a14cd26b66a0b8ac5e0a4 Mon Sep 17 00:00:00 2001 From: Tengfei Niu Date: Tue, 17 Nov 2020 15:34:05 +0800 Subject: [PATCH] book: fix incorrect return value description of std::weak_ptr expired (#144) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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`. --- book/en-us/05-pointers.md | 4 ++-- book/zh-cn/05-pointers.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/book/en-us/05-pointers.md b/book/en-us/05-pointers.md index d2e6eb0..4f30d8d 100644 --- a/book/en-us/05-pointers.md +++ b/book/en-us/05-pointers.md @@ -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 -Creative Commons License
This work was written by [Ou Changkun](https://changkun.de) and licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. The code of this repository is open sourced under the [MIT license](../../LICENSE). \ No newline at end of file +Creative Commons License
This work was written by [Ou Changkun](https://changkun.de) and licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. The code of this repository is open sourced under the [MIT license](../../LICENSE). diff --git a/book/zh-cn/05-pointers.md b/book/zh-cn/05-pointers.md index 99d76a4..a083027 100644 --- a/book/zh-cn/05-pointers.md +++ b/book/zh-cn/05-pointers.md @@ -175,7 +175,7 @@ int main() { 在上图中,最后一步只剩下 B,而 B 并没有任何智能指针引用它,因此这块内存资源也会被释放。 -`std::weak_ptr` 没有 `*` 运算符和 `->` 运算符,所以不能够对资源进行操作,它的唯一作用就是用于检查 `std::shared_ptr` 是否存在,其 `expired()` 方法能在资源未被释放时,会返回 `true`,否则返回 `false`。 +`std::weak_ptr` 没有 `*` 运算符和 `->` 运算符,所以不能够对资源进行操作,它的唯一作用就是用于检查 `std::shared_ptr` 是否存在,其 `expired()` 方法能在资源未被释放时,会返回 `false`,否则返回 `true`。 ## 总结