Confusion regarding name hiding and virtual functions
c++, name-hiding, overriding, virtual
Solution
You are confusing virtual functions calls and overload resolution.
All derived classes have vtables containing all virtual functions, from the base class and any additional own virtual functions. This is used to resolve calls at runtime, like in your case 2).
In case 1) you get an error from overload resolution at compile time. Due to name hiding, class `Derived` only has one callable function. Your only choice is to call that function, with an `int*`.
Problem
Refering another so question Consider the code : ``` class Base { public: virtual void gogo(int a){ printf(" Base :: gogo (int) \n"); }; virtual void gogo(int* a){ printf(" Base :: gogo (int*) \n"); }; }; class Derived : public Base{ public: virtual void gogo(int* a){ printf(" Derived :: gogo (int*) \n"); }; }; int main(){ // 1) Derived * obj = new Derived ; obj->gogo(7); // this is illegal because of name hiding // 2) Base* obj = new Derived ; obj->gogo(7); // this is legal } ``` For case 2) The call `obj->gogo(7)` is resolved at run time. Since `obj->gogo(7)` is legal. It seems to imply that vtable of `Derived` contains ptr to `virtual void gogo(int a)` which should have been hidden. My confusion is , since name hiding causes case 1) to be illegal, then how the call in 2) is resolved at run time a) Does vtable of Derived contains pointer to gogo(int). b) If a) is not True, Does call resolution for virtual functions proceeds to vtable of base class.