D
DKumar
class A{
virtual void f1(){}
};
class B : public A{
void f1(){}
};
int main()
{
A *pa = new B;
pa->f1();
}
In the above case, why compiler doesn't know which f1() I am trying to call? It has the address of B, so obviously it has to call B's f1(). Why virtual table needed here to know which f1 needs to be called?
virtual void f1(){}
};
class B : public A{
void f1(){}
};
int main()
{
A *pa = new B;
pa->f1();
}
In the above case, why compiler doesn't know which f1() I am trying to call? It has the address of B, so obviously it has to call B's f1(). Why virtual table needed here to know which f1 needs to be called?