What's the rationale behind the hiding rule in C++?
class A { void f(int); }
class B : public A { void f(double); } // B::f(int) is hidden
If it is a meaningful feature I think it should also be possible to hide functions without defining new functions with the same name: something like this:
class B : public A { hide void f(double); }
but this is not possible.
I don't think it simplifies compilers job, since compilers must anyway be able to unhide functions when you explicitly use the
using
directive:class B : public A { using A::f; void f(double); } // B::f(int) NOT hidden
So, how come there is a hiding rule?
A::f
into the in memory representation of the class. When it tries to resolve a call, it only needs to go back as far as needed until it finds the first occurrence of the identifier. There is no need to keep going back accross possibly multiple paths to bring all possible identifiers into scope. The same goes for the fact that a member method will hide a namespace level function... – Coady=delete
. – Vollmerclass A : protected B { ... };
instead ofpublic
. Sorry for beating a dead horse. – Coarctate