C++: Overloading Derived Class Assignment

Copying parent class members

If there is a parent (base) class, those fields must also be copied. You can accomplish this with the following cryptic statement,
where Parent is the name of the base class.
//--- file Parent.h
class Parent {...};   // declaration of base class
//--- file Child.h
#include "Parent.h"
class Child : public Parent { // declaration of derived class
    Child& Child::operator=(const Child& source);
};//end class Child
//--- file Child.cpp
#include "Child.h"
Child& Child::operator=(const Child& source) {
    if (this != &source) {
        . . . // copy all our own fields here.
    return *this;
}//end operator=

See Also

Overloading Assignment