My question is with a link to this question , which explains how virtual functions work in the case of slicing objects that ultimately call the virtual function of the base class and Wikipedia article , which explains the structure of the virtual table for the derived class for the code below
class A{ public: virtual void func(){ cout<<"\n In A:func";} }; class B:public A{ public: virtual void func(){ cout<<"\n In B:func";} }; main(){ A *ptr1 = new B(); A oA = *ptr1; oA.func(); } DerviedClassObjectB: +0: pointer to virtual method table of B virtual method table of B: +0: B::func
Above the exits of the program "In A :: func".
But as without a virtual table for class B, knowledge of the base class A :: func ends with a call to A :: func
Poorna
source share