Consider the code :
#include
class Base {
public:
virtual void gogo(int a){
printf(\" Base :: gogo (int) \\n\");
};
v
Name hiding makes sense because it prevents ambiguities in name resolution.
Consider this code:
class Base
{
public:
void func (float x) { ... }
}
class Derived: public Base
{
public:
void func (double x) { ... }
}
Derived dobj;
If Base::func(float)
was not hidden by Derived::func(double)
in Derived, we would call the base class function when calling dobj.func(0.f)
, even though a float can be promoted to a double.
Reference: http://bastian.rieck.ru/blog/posts/2016/name_hiding_cxx/