The Wayback Machine - https://web.archive.org/web/20201129040042/https://github.com/changkun/modern-cpp-tutorial/pull/144
Skip to content
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

Fix error #144

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

Fix error
资源尚存在时,`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`

This comment has been minimized.

@changkun

changkun Nov 17, 2020
Owner

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

This comment has been minimized.

@spartucus

spartucus Nov 17, 2020
Author Contributor

Sure thing!

This comment has been minimized.

@spartucus

spartucus Nov 17, 2020
Author Contributor

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

Thank you so much for your contribution!

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

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.