TITLE: Inheritance - interface versus implementation PROBLEM: mikeg@cs.umbc.edu (Mike Grasso) The following example should demonstrate the proper use of constructors with virtual base classes. [...] class CustEmp : public Customer, public Employee { public: CustEmp(){} CustEmp(char *a, char *b, int c, char *d) : Person(a,b), Customer(a,b,c), Employee(a,b,d) {} RESPONSE: maxtal@physics.su.OZ.AU (John Max Skaller), 20 May 94 This is correct, but what a pain having to pass 'a' to all three base constructors, knowing only the Person() constructor will actually initialise the base! Its not so bad with only 4 classes in a diamond, but with more complex architectures its really horrible. No one has found a way around it. Now, I suspect that the 'proper example' above is actually not so proper: the base should have been abstract, and an instance of it derived from only in CustEmp. This allows the virtual base to have 'no' constructors. More completely, here is the correct architecture: AbstractPerson / \ AbsCust AbsEmp / \ / \ ConcreteCust AbsCustEmp ConcreteEmp \ | / ConcreteCustEmp Yes, its more complex. But it obeys a golden rule: never derive from a concrete class. Is the original 'proper' solution wrong? No. Its just not as flexible. And it cant require passing any initialiser more than once. [ John has frequently advocated complete separation of interface from implementation. One of the "rules" he espouses is to have your class heirarchy composed of abstract classes to define interfaces. A specific implementation should be implemented as a concrete classes derived from an abstract class. If you want to inherit implementation, you should multiply derive - one parent gives you the interface, the other(s) gives you the implementation. -adc ]