小编mia*_*eak的帖子

有没有办法在没有 std::move 的情况下在 C++ 中调用移动赋值运算符?

我想知道是否可以在不使用标准库 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);吗?

c++ c++11 c++14 c++17

3
推荐指数
1
解决办法
114
查看次数

标签 统计

c++ ×1

c++11 ×1

c++14 ×1

c++17 ×1