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

问题:在使用weak_ptr解决循环引用的例子中,有两行代码是不是写反了 #1

Closed
gaoxinge opened this issue Dec 30, 2021 · 1 comment

Comments

@gaoxinge
Copy link

@archibate

下面两行代码是不是写反了:

course/02/24/3.cpp

Lines 13 to 14 in 3940bba

parent->m_child = std::move(child); // 移交 child 的所属权给 parent
child->m_parent = parent.get();

是不是应该先获取裸指针,再使用std::move移交拥有权,如下:

 child->m_parent = parent.get(); 
 parent->m_child = std::move(child);  // 移交 child 的所属权给 parent 
@archibate
Copy link
Collaborator

说的对!感谢提醒。

@gaoxinge gaoxinge closed this as completed Jan 1, 2022
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

No branches or pull requests

2 participants