默认复制移动构造函数效率不同

发布于 2025-01-14 12:54:49 字数 187 浏览 1 评论 0原文

如果编译器提供的默认复制构造函数仅进行浅复制(将堆中成员的指针复制到目标对象相应的成员字段),那么默认复制构造函数有什么区别> 和默认移动构造函数

我认为默认移动构造函数不应该比默认复制构造函数更有效,因为没有发生深度复制。我说得对吗?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薄暮涼年 2025-01-21 12:54:49

默认复制构造函数和默认移动构造函数有什么区别?

默认复制构造函数对数据成员进行逐成员复制,而默认移动构造函数对数据进行逐成员移动成员。也就是说,默认的移动构造函数会窃取资源,而不是从传递的参数中复制资源。

what is the difference between default copy constructor and default move constructor?

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文