TITLE: vtables and inheritance [ The term vtable refers to a table associated with a given class that is used to support virtual functions. It is technically a detail of a particular implementation of C++, but it is worth having a basic understanding. A table is usually allocated for each class (not instance), that inherits or declares virtual functions. Each slot in the table is effectively a "pointer" to a virtual function. Each instance typically has a pointer to one of these tables that is inserted by the compiler. -adc ] PROBLEM: Rabi Arumugham My question is "Does an X object have two V-tables associated with it? ie two V - Table pointers?" [...] Becuase A , B, Y and Z objects will have only V-table pointer. When an X object is placed along with A and B objects in a Base1 array and when functions b11() and b12() are called through a Base1 pointer the V-Table for the Base1 class heirarchy has to be used right? Similar argument for the Base2 array. So now how does the structure of the X object differ from those of A,B, Y, and Z with respect to virtual call implementation? RESPONSE: clamage@Eng.Sun.COM (Steve Clamage), 2 Oct 95 Implementations vary slightly, but when you have multiple inheritance, you always need one vtable (and pointer) for each direct base class. Each base class (direct or indirect) might need its own vtable (and pointer). As an optimization, if the left-most direct base class is not a virtual base class, it can share a vtable (and pointer) with the derived class. If there are no virtual base classes, this means that the chain of left-most base classes share a single vtable and pointer with the most-derived class. In the limiting case of single inheritance, all the base classes are left-most, and there is a single vtable and pointer for the entire hierarchy. Example: A B C D \ / \ / E F \ / \ / G If none of these classes is virtual, G-E-A can share a common vtable pointer and F-C share a common vtable pointer, for a total of 4 vtable pointers and 4 vtables in the hierarchy, assuming all classes have or inherit at least one virtual function. A, B, C and D cannot share a vtable or pointer, and E and F cannot share a vtable or pointer: Even if the sets of their virtual functions were identical (all overridden by G), their relative locations in the object are different, requiring different adjustments to "this" when the functions are called. That is, a base-class subobject can share the derived-class vtable if it has the same address as the derived class. A, E, and G can have the same address, but E and F cannot in general, nor can A and B, nor C and D.