0

在子类中覆盖移动赋值运算符并在调用基类的移动赋值运算符后移动子类的字段时,我收到了来自 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

覆盖操作员的正确方法是什么?

4

0 回答 0