Re: Multiple Inheritance and vptr
Venkat wrote:
> Considering the following class hierarchy,
> class Base1
> {
> public:
> Base1(){}
> virtual void MyFun()
> {
> }
> };
> class Base2
> {
> public:
> virtual void MyFun1()
> {
> }
> };
> class Derived1 : public Base1, public Base2
> {
> public:
> virtual void MyFun2()
> {
> }
> };
> I know that Derived1 has 2 vptrs and 2 vtables. I want to
> know to which vtable MyFun2() gets added? To vtable from
> Base1 or vtable from Base2?
First, of course, it's all implementation defined; an
implementation doesn't even have to use vtables. Typically,
however, there will be at least five different vtables in the
above hierarchy: Base1_vtbl (used during the construction of
Base1 -- doesn't know about any derived class), Base2_vtbl (as
above, but for Base2), and Base1_in_Derived1_vtbl and
Base2_in_Derived1_vtbl, used in the complete object, and
Derived1_vtbl. In practice, in the absence of virtual
inheritance, all implementations I know of will merge
Base1_in_Derived1_vtbl (in fact, whichever base class is
mentioned first) and Derived1_vtbl. In the absence of virtual
inheritance only, however.
--
James Kanze kanze.james@neuf.fr
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]