Open
Conversation
Suzcer
commented
May 15, 2022
- 避免函数参数不必要的拷贝使用const List&或List const&
- 实现深拷贝步骤:将other的先顺序遍历至结尾,再倒序遍历添加(因为只有push_front函数)
- 改进Node的构造函数可以添加explicit,防止隐式转换
- 其他尚未解决,有些内容不了解,比如如果改用unique_ptr,如何在拷贝构造函数中进行结点的遍历?(因为不能将unique_ptr赋值给其他tmp,从而使得tmp去遍历等等);也不清楚为什么可以删除拷贝赋值函数,以及最后并未进行资源的释放等等。
Author
|
Contributor
|
> unique_ptr如何遍历?因为不能赋值给其他tmp
你可以用get()函数获取原始指针用于遍历,例如: `Node * tmp = uniq.get()`,这个tmp就可以浅拷贝了
无法顺畅的大口呼吸,是活着的最好证明
…---Original---
From: ***@***.***>
Date: Sun, May 15, 2022 16:14 PM
To: ***@***.***>;
Cc: ***@***.***>;
Subject: Re: [parallel101/hw02] Suzcer's first version (PR #58)
避免函数参数不必要的拷贝使用const List&或List const&
实现深拷贝步骤:将other的先顺序遍历至结尾,再倒序遍历添加(因为只有push_front函数)
改进Node的构造函数可以添加explicit,防止隐式转换
其他尚未解决,有些内容不了解,比如如果改用unique_ptr,如何在拷贝构造函数中进行结点的遍历?(因为不能将unique_ptr赋值给其他tmp,从而使得tmp去遍历等等);也不清楚为什么可以删除拷贝赋值函数,以及最后并未进行资源的释放等等。
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Author
|
谢谢小彭老师,我还有一个问题,就是当我想要换成unique_ptr的时候,并没有找到push_front很好的解法,可以指点一下吗?
比如下面这样写就会导致head为NULL,于是下面的if也会失效
***@***.***
From: 彭于斌
Date: 2022-05-15 16:22
To: parallel101/hw02
CC: SU; Author
Subject: Re: [parallel101/hw02] Suzcer's first version (PR #58)
> unique_ptr如何遍历?因为不能赋值给其他tmp
你可以用get()函数获取原始指针用于遍历,例如: `Node * tmp = uniq.get()`,这个tmp就可以浅拷贝了
无法顺畅的大口呼吸,是活着的最好证明
…---Original---
From: ***@***.***>
Date: Sun, May 15, 2022 16:14 PM
To: ***@***.***>;
Cc: ***@***.***>;
Subject: Re: [parallel101/hw02] Suzcer's first version (PR #58)
避免函数参数不必要的拷贝使用const List&或List const&
实现深拷贝步骤:将other的先顺序遍历至结尾,再倒序遍历添加(因为只有push_front函数)
改进Node的构造函数可以添加explicit,防止隐式转换
其他尚未解决,有些内容不了解,比如如果改用unique_ptr,如何在拷贝构造函数中进行结点的遍历?(因为不能将unique_ptr赋值给其他tmp,从而使得tmp去遍历等等);也不清楚为什么可以删除拷贝赋值函数,以及最后并未进行资源的释放等等。
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.