在GCC 4.6中,即使當由於移動構造函數而隱式刪除子對象的賦值操作符時,也可能繼承父對象的賦值操作符。在後來的GCC版本(以及Clang)中,這是不可能的。讓子類使用父代賦值操作符的正確方法是什麼?當子對象被隱式刪除時繼承父賦值操作符
struct A
{
A & operator=(A const & other) = default;
};
struct B : public A
{
B() {}
B(B && other) {}
using A::operator=;
};
int main()
{
B b1, b2;
b1 = b2; // error: use of deleted function because B's operator= is implicitly deleted due to move constructor
return 0;
}