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.
Base::gogo(int)
is indeed hidden byDerived::gogo(int*)
. But ausing Base::gogo;
statement in theDerived
class would solve this particular problem. – Typical