How vptr and vtable works
Assume that class B is base class and D is derived class. Both has virtual function test(). Now , in main function; I have B* pB = new D; 1. Does this means after compilation , both class has vtable ? B class vtable points to function test from B and D class vtable points to function test from D. 2. As pb is pointing to D, pb will point to vptr of D. But when this happens and how ? We just created two different vtable at compile time.. when run time linking happens and how ? Different articles speaks that constructor implements additional responsibilities of binding vtable to vptr for each object. Is this understanding correct... If so, how ? Here , we are not creating any object due to pointer and new still how linking happens from constructor ?