当调用基类的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
重写操作员的正确方法是什么?