Why is an assignment to a base class valid, but an assignment to a derived class a compilation error?

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)