Skip to content

Fix error #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 17, 2020
Merged

Fix error #144

merged 2 commits into from
Nov 17, 2020

Conversation

spartucus
Copy link
Contributor

@spartucus spartucus commented Nov 17, 2020

Description

Fix error, while the resource of std::shared_ptr exists, the expired() method of std::weak_ptr returns false, otherwise returns true.

Change List

  • Fix error of expired() return value

Reference

https://en.cppreference.com/w/cpp/memory/weak_ptr/expired

说明

修复错误,std::shared_ptr 资源尚存在时,std::weak_ptrexpired() 方法返回 false, 否则返回 true

变化箱单

  • 修复了关于 std::weak_ptrexpired() 方法返回值错误

参考文献

https://en.cppreference.com/w/cpp/memory/weak_ptr/expired

资源尚存在时,`std::weak_ptr` 的 `expired()` 方法返回 `false`, 否则返回 `true`。
@@ -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`。
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please maybe also fix the error in book/en-us/05-pointers.md?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Fix error, while the resource of `std::shared_ptr` exists, `std::weak_ptr`'s `expired()` method returns `false`, otherwise it returns `true`.
Copy link
Owner

@changkun changkun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for your contribution!

@changkun changkun merged commit 1e78a01 into changkun:master Nov 17, 2020
@spartucus spartucus deleted the patch-1 branch November 17, 2020 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants