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 redefine (“override”) a member function that is non-virtual in a base class?

0
Posted

Should a derived class redefine (“override”) a member function that is non-virtual in a base class?

0

FAQ: You can do that, but you shouldn’t. Experienced programmers sometimes do that for various reasons. Remember that the user-visible effects of both versions of the functions must be identical. FQA: Here’s a trade secret: not so experienced programmers do that, too. For the umpteen time: why does this compile? This particular case doesn’t seem to be an unintended side effect; it’s a feature with elaborate design (there’s all this nonsense with using names from the base class shadowed by functions with the same name, etc.). The redefinition-looking-like-an-override is overloading on steroids: it’s even less useful and has even higher obfuscation potential. And it’s only one of the zillions of various name binding rules – the bits of C++ making it impossible to decipher what code is actually called by f(x).

Related Questions

What is your question?

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

Experts123