Wednesday, 2 November 2016

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

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...