www.digitalmars.com         C & C++   DMDScript  

c++.chat - How does multiple Inheritance Work?

Just out of interest,

How does the compiler deal with multiple inheritance?  Originally I 
thought the compiler would generate a separate V-table for each class 
however I can't see how that would work for when the class is upcasted.

ie

class A
{
	virtual void a();
};

class B
{
	virtual void b();
}

class AB : public A, public B
{
	virtual void c();
};

...
AB *ab = new AB();
A *a = dynamic_cast<A*>(ab);
B *b = dynamic_cast<B*>(ab);
a->a(); //Ok for method which is in "slot 1" of the vtable
b->b(); //The function offset in b is in the same offset as a right?  Ok 
you probably could offset all b calls into the second slot and have lots 
of padding but that wouldn't work across libraries.

I read somewhere that gcc use pointer fixups.  What does that mean? 
What does DMC do?  What do other compilers use?  Do they optimise for 
multiple interface inheritance (which I guess is an easier case?)  What 
other optimisation do they perform?

I thought I understood inheritance but this throws a spanner in the works.

-Cheers
Joel
Oct 31 2006