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

Viewed 1658

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; throw an error, while a = b; is perfectly fine?

6 Answers
Related