移动构造函数是否自动生成? [英] Are move constructors produced automatically?

查看:1882
本文介绍了移动构造函数是否自动生成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大类持有大量的STL容器。

编译器会自动创建一个移动构造函数,将这些容器移动到目标或我必须自己做?

I have a big class holding a lot of STL containers.
Will the compiler automatically make a move constructor that will move those containers to the target or I have to make my own?

推荐答案

类X的移动构造函数隐式声明为默认

A move constructor for a class X is implicitly declared as defaulted exactly when



  • X没有用户声明的复制构造函数,

  • X没有用户声明的复制赋值运算符, li>
  • X没有用户声明的移动赋值运算符,

  • X没有用户声明的析构函数,

  • 移动构造函数不会隐式定义为已删除。

  • X does not have a user-declared copy constructor,
  • X does not have a user-declared copy assignment operator,
  • X does not have a user-declared move assignment operator,
  • X does not have a user-declared destructor, and
  • the move constructor would not be implicitly defined as deleted.

如果你的类有一个没有移动构造函数的类型数据成员,你的类不会得到一个移动构造函数,即使它没有任何复制/移动构造函数声明,因为隐式声明的move构造函数将被定义为已删除(因为该数据成员)。

So for example, if your class has a class type data member that does not have a move constructor, your class will not get a move constructor even if it doesn't have any copy/move constructor declared, because the implicitly declared move constructor would be defined as deleted (because of that data member).

这篇关于移动构造函数是否自动生成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆