我想知道是否可以在不使用标准库 std::move 的情况下调用移动赋值运算符。
例如,如果我打电话:
class A {
private:
char* data;
public:
// move constructor
A(A&& other) : data(other.data) {
// we steal the pointer!
other.data = NULL;
}
// move operator=
A& operator=(A&& other) {
if (this != &other) {
delete data;
data = other.data;
data.foo = NULL;
}
return *this;
}
};
int main(){
A objA;
A objB;
objB = std::move(objA);
}
Run Code Online (Sandbox Code Playgroud)
我现在可以写其他东西objB = std::move(objA);吗?