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,
this->Parent::operator=(source);
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
public:
Child& Child::operator=(const Child& source);
};//end class Child
//--- file Child.cpp
#include "Child.h"
Child& Child::operator=(const Child& source) {
if (this != &source) {
this->Parent::operator=(source); // Or no need hiden this pointer.
. . . // copy all our own fields here.
}
return *this;
}//end operator=
Wednesday, August 19, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment