Assignment Operator in C++

Step for assignment operator
  1. check for self assignment
  2. call base assignment operator. // this should take care for copy constructor.
  3. remove existing allocated memory for members
  4. assign memory for members
  5. do assignment for all data members.
  6. 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. :)