Does c++ support multilevel and multiple inheritance?

Showing Answers 1 - 2 of 2 Answers

samiksc

  • Jan 20th, 2006
 

Yes,

In C++ we can derive a class C from B which is derived from A -- multilevel inheritance.

In C++ we can derive a class D from two base classes A and B -- multiple inheritance. This may cause a problem in case A and B are derived from a single base class say P. When a D's method refers to a public/protected data member of P (the uppermost parent) there are two paths available -- A::var or B::var -- here the compiler gives an error. To avoid this problem A and B need to be 'virtually' derived from P. If they are virtually derived then only one copy of P's data members exist for both A and B objects.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions