为什么会这样:
struct A
{
A(int) {
cout << "construct from int" << endl;
}
A(A&&) = delete;
A(const A &) {
cout << "copy constructor" << endl;
}
};
int main(){
A a = 0;
}
出现错误:
error: use of deleted function ‘A::A(A&&)’
为什么当我添加这样的移动构造函数时
A(A&&) {
cout << "move constructor" << endl;
}
程序编译正常,但输出为空。
construct from int
据我所知,编译器要求构造函数但不使用它。为什么?这对我来说毫无意义。
附注:我认为
A a = 0;
等同于
A a = A(0);
但为什么既没有调用移动构造函数,也没有调用移动赋值运算符呢?