How is C++'s multiple inheritance implemented?
c++, compiler-construction, inheritance, language-implementation, multiple-inheritance
Solution
The following paper from the creator of C++ describes a possible implementation of multiple inheritance:
Multiple Inheritance for C++ - Bjarne Stroustrup
Problem
Single inheritance is easy to implement. For example, in C, the inheritance can be simulated as: ``` struct Base { int a; } struct Descendant { Base parent; int b; } ``` But with multiple inheritance, the compiler has to arrange multiple parents inside newly constructed class. How is it done? The problem I see arising is: should the parents be arranged in AB or BA, or maybe even other way? And then, if I do a cast: ``` SecondBase * base = (SecondBase *) &object_with_base1_and_base2_parents; ``` The compiler must consider whether to alter or not the original pointer. Similar tricky things are required with virtuals.