Step for assignment operator
- check for self assignment
- call base assignment operator. // this should take care for copy constructor.
- remove existing allocated memory for members
- assign memory for members
- do assignment for all data members.
- return *this.
Derived& Derived::operator=(const Derived& rhs)
{
if (this == &rhs) return *this;
// equality based on address or value identity.
static_cast<Base&>(*this) = rhs; // call this->Base::operator=
y = rhs.y;
return *this;
}
--------------still in draft-------------------
No comments:
Post a Comment
would you like it. :)