This was an interview question. Consider the following:
struct A {};
struct B : A {};
A a;
B b;
a = b;
b = a;
Why does b = a;
Because the implicitly declared copy assignment operator of B
hides the implicitly declared copy assignment operator of A
.
So for the line b = a
, only the the operator=
of B
is a candidate. But its parameter has type B const&
, which cannot be initialized by an A
argument (you would need a downcast). So you get an error.