Assignment operator inheritance

Actually, what is called is the implicitly defined operator = for Derived. The definition provided by the compiler in turn calls operator = for the Base and you see the corresponding output. The same is with the constructor and destructor. When you leave it to the compiler to define operator =, it defines it as follows:

Derived& operator = (const Derived& rhs)
{
    Base1::operator =(rhs);
    ...
    Basen::operator =(rhs);
    member1 = rhs.member1;
    ...
    membern = rhs.membern; 
}

where Base1,...,Basen are the bases of the class (in order of specifying them in the inheritance list) and member1, ..., membern are the members of Derived (not counting the members that were inherited) in the order you declared them in the class definition.

Leave a Comment