这是我的原型,我可以为班级编写复制和移动赋值操作符吗?
MyClass& operator=(MyClass rhs); // copy assignment
MyClass& operator=(MyClass &&rhs); // move assignment
但是,当我打电话
MyClass a, b;
a = std::move(b);
,有错误。
556 IntelliSense: more than one operator "=" matches these operands:
function "MyClass::operator=(MyClass rhs)"
function "MyClass::operator=(MyClass &&rhs)"
operand types are: MyClass = MyClass
,编译器回报:
Error 56 error C2593: 'operator =' is ambiguous
智能感知错误并不总是真正的编译器错误。 – drescherjm
尝试更改复制赋值运算符以获取*引用*,最好是一个常量引用。 –
“MyClass”类型的右值同时绑定到两个函数。这确实是不明确的。 –