   Inheritance
  I have a question about deriving classes... is it possible to have the following scenario:Say i have classes A, B, C and D...Class A is a base class.Class B is derived from class A.Class C is derived from class A.Is it possible to have Class D derived from classes B and C?I tried compiling it and was running into some strange compile errors, so i was wondering if these kind of thing is possible or not? 
  Yes, it is, but it isn''t regarded as good design. A nickname applied to it is the "dreaded diamond" (I''ll let you google that).  You also end up causing the following:The topmost class (A) actually will have two instances inside a D instance when you don''t use virtual inheritance:D - B - AD - C - AIf you use virtual inheritance, then the A instance is shared between B and C. ;  I think its only possible if the only functions that are common between B and C are pure virtual ;  beat me to it, and did a better job ;quote:Original post by antareus  Yes, it is, but it isn''t regarded as good design. A nickname applied to it is the "dreaded diamond" (I''ll let you google that).  You also end up causing the following:The topmost class (A) actually will have two instances inside a D instance when you don''t use virtual inheritance:D - B - AD - C - AIf you use virtual inheritance, then the A instance is shared between B and C.   Thanks for the info, i''ve decided to go ahead and do it anyway using virtual inheritance. Is that the only use for virtual inheritance or does it serve some other more general purpose?Anyway, I hope it doesn''t come back to haunt me later. But I can''t see any other way around the problem i have other than massive amounts of Cut & Pasting (not good ). ;  Yes, that is the only use of virtual inheritance. However, using it has some more side effects on your code. First of all, function calls are resolved by dominance (look it up) and generally is less efficient. When casting down in virtual MI, remember to always use dynamic_cast. Also, when you have two functions of the same name in parent classes, you won't be able to overload both of them in your most derived class unless you introduce auxiliary classes (Effective C++). Finally, I think the only valid use for MI (not interface MI, which is good IMO) is to redefine the interface of some library which you can't modify because you don't have the sources (and even this can be accomplished by design patterns, thus avoiding MI altogether). Tread carefully. [edited by - fallenang3l on February 9, 2004 5:23:34 PM];  Well in C++ it''s nontrivial or worse, in Eiffel it''s no problem at all. In Eiffel you can rename or join features you inherit from your base classes. If you think there should only be one name-feature, great, just join both names you inherited. If you inherit 2 identically named features just rename one of them. ;  Hello SpaceDude,I belive that if none of your classes has virtual function that you can still use virtual base classes without having to use dynamic_cast.The reason is there is no virtual table so no need to dynamic_cast.dynamic_cast is used only to make sure the virtaul tables are correct for the object your casting to.The virtual for base inhertance is only used to tell the compiler there is only one copy of the base class(es).Lord Bart ;FAQ YOU MAN ;  Ok thanks for the info, very helpfull... I''m getting warnings in MSVC++ .NET when i compile though... Telling me that certain functions have been resolved by dominance like fallenang3l said. But why is it giving me a warning? That is what i want it to do... I''ve disabled that warning message for the time being, but is there something i can do in the code to get rid of the warnings? 