Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Should a derived class replace (“override”) a non-virtual function from a base class?

0
Posted

Should a derived class replace (“override”) a non-virtual function from a base class?

0

It’s legal, but it ain’t moral. Experienced C++ programmers will sometimes redefine a non-virtual function (e.g., the derived class implementation might make better use of the derived class’s resources for efficiency), or to get around the hiding rule[23.3]. However the client-visible effects must be identical, since non-virtual functions are dispatched based on the static type of the pointer/reference rather than the dynamic type of the pointed-to/referenced object.

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.