默认复制移动构造函数效率不同
如果编译器提供的默认复制构造函数仅进行浅复制(将堆中成员的指针复制到目标对象相应的成员字段),那么默认复制构造函数有什么区别> 和默认移动构造函数?
我认为默认移动构造函数不应该比默认复制构造函数更有效,因为没有发生深度复制。我说得对吗?
if default copy constructor provider by compiler only make a shallow copy(copy the pointer of a member in heap to target object's corresponding member field), what is the difference between default copy constructor and default move constructor?
I think default move constructor should not be more more efficient than default copy constructor, as no deep copy happened. Am I right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认复制构造函数对数据成员进行逐成员复制,而默认移动构造函数对数据进行逐成员移动成员。也就是说,默认的移动构造函数会窃取资源,而不是从传递的参数中复制资源。
A default copy constructor does memberwise copy of the data members while a default move constructor does memberwise move of the data members. That is, the default move constructor steal resources instead of copying them from the passed argument.