我有这样一个类:
class myClass
{
int x[1000];
public:
int &getx(int i)
{
return x[i];
}
}
请注意,我没有在这里提供 move 结构。
如果我使用下面的代码:
myClass A;
auto B=std::move(a);
是 A move 到 B 还是由于我没有提供 move 构造函数,A 被复制到 B?
对象是否有任何默认的 move 构造函数?如果是,它如何处理指针和动态分配的数组?
最佳答案
虽然您没有提供显式 move 构造函数,但编译器为您提供了隐式 move 构造函数。
If the definition of a class X does not explicitly declare a move constructor, one will be implicitly declared as defaulted if and only if
- X does not have a user-declared copy constructor, and
- 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.
所以你的问题的答案是:不,A 没有被复制到 B。
不清楚你在其他问题中问的是什么。请指定更多详细信息。
关于c++ - 我可以将 std::move 与不提供 move 构造函数的类一起使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50609626/