I\'ve wanted to prevent even the hiding of base class non-virtual function for a while since I learned C++, and I\'m not sure if this would be ethical, but C++ 11 features g
I'd say that, yes, it's bad practice. You introduced polymorphism when you didn't want it, just to prevent name hiding.
But what's so bad about name hiding? Obviously, for whatever reason, the design of Derived
desires to hide the function foo
in its base class; that is what it does — perhaps it makes its own call to Base::foo
then performs some additional activity that is required within Derived
.
Trying to subvert that is bad enough; trying to do it by co-opting language features that you don't want is even worse.
If you really need to call the base function, use derived.Base::foo()
, but be aware that you are essentially breaking the API of the class Derived
, which you should instead use as documented.