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

finish hw02 #67

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

finish hw02 #67

wants to merge 1 commit into from

Conversation

QifanWang
Copy link

  • 避免函数参数不必要的拷贝:将 print 函数参数改为 const ref 类型。
  • 修复智能指针造成的问题:shared_ptr 会造成循环引用带来内存泄漏。
  • 改用 unique_ptr<Node>:将 Node 类型的 nextprev 字段改为 unique_ptr<Node> 与 raw pointer 类型。
  • 实现拷贝构造函数为深拷贝:遍历 ListNode 进行拷贝。
  • 说明为什么可以删除拷贝赋值函数:删除后,在原来拷贝赋值的 call site 可以编译器可以处理为 拷贝构造(构造出一个右值) + 移动赋值 的调用。
  • 改进 Node 的构造函数:改用 member list initialization 并初始化所有成员,尤其是 raw pointer 的初始化。这里不用 explicit 修饰 constructor 是觉得代码中没有这类的隐式构造,我觉得暂时无必要。

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.

1 participant