替代移动分配运算符

时间:2018-12-04 08:19:49

标签: c++ clang-tidy

当调用基类的move-assignment运算符覆盖子类中的move-assignment运算符并移动子类的字段时,我收到clang-tidy的警告。

示例:

class Base{
     ...
     Base& operator=(Base&& other) {...}
};

class Sub : public Base {
     OtherClass n;
     Sub& operator=(Sub&& other) {
         Base::operator=(std::move(other));
         n = std::move(other.n); // <-- Here is the warning
         return *this;
     }
};

我得到的警告是:

Clang-Tidy: 'other' used after it was moved

重写操作员的正确方法是什么?

0 个答案:

没有答案