Tuesday, 20 February 2018

c++ - derived assignment operator calling the one from a base



In the best rated answer to the question from this link, I don't understand how the derived assignment operator calls the assignment operator from the base class, i.e., this in this part of the code:



Derived& operator=(const Derived& d)
{
Base::operator=(d);

additional_ = d.additional_;
return *this;
}


what does



Base::operator=(d)



mean? What does it do? Cheers!


Answer



It's just a call to a member function on the current object. The current object inherited a function whose fully-qualified name is Base::operator=, and you can call it just like any other non-static member function.


No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...