Here are two classes that overload a virtual function:
class Base
{
public:
virtual void func(int) {
cout<<"base int"<<endl;
}
virtual void func(double) {
cout<<"base double"<<endl;
}
};
class Deri: public Base
{
public:
virtual void func(int) {
cout<<"deri int"<<endl;
}
};
I use these classes here:
int main() {
Base * ptr = new Deri;
ptr->func(3.0); //"base double"
static_cast<Deri *>(ptr)->func(3.0);//"deri int"
return 0;
}
I expected that both calls are for the base double overload, but I get the following output:
base double
deri int
When I add the following "using" statement in Deri
:
using Base::func;
I get all overloaded functions from the Base class and it works as expected.
What happens when I don't use this "using statement" ? I assume ptr->func(3.0)
and static_cast<Deri*>->func(3.0)
look for the same vtable. But how they look for different functions? What the vtable of Class Deri look like?