why 2 vfptrs in case of virtual inheritance?
-
Hi all. Here are the two classes one base and other Derived ( virtually inherited from Base) Class Base { Public: Virtual void FunB(){} }; Class Derived: virtual public Base { Public: Virtual void FunD(){} }; When I derived class Derived virtually from Base, and when I saw the memory layout of objects of Derived in debug window; I saw two separate vfptrs; one for Base and one for Derived. But if I do not derive class Derived virtually from Base, then there is only single vfptr in object of Derived class? Why an extra vfptr is added/required in case of virtual inheritance?
Sameer Thakur
-
Hi all. Here are the two classes one base and other Derived ( virtually inherited from Base) Class Base { Public: Virtual void FunB(){} }; Class Derived: virtual public Base { Public: Virtual void FunD(){} }; When I derived class Derived virtually from Base, and when I saw the memory layout of objects of Derived in debug window; I saw two separate vfptrs; one for Base and one for Derived. But if I do not derive class Derived virtually from Base, then there is only single vfptr in object of Derived class? Why an extra vfptr is added/required in case of virtual inheritance?
Sameer Thakur
Try reading this article[^] in the C++ FAQ, especially section 25.9 on virtual inheritance.
Software Zen:
delete this;