我有一个很大的类(class),里面有很多 STL 容器。
编译器会自动创建一个移动构造函数,将这些容器移动到目标,还是我必须自己创建?
最佳答案
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 构造函数将被定义为已删除(因为该数据成员)。
关于c++ - 移动构造函数是自动生成的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8283589/