Virtual Base Class : (Multipath Inheritance)

By
Last updated:

The from of inheritance which derives a new class by multiple inheritance of base class, which are derived earlier from the same base class, is known as multipath inheritance. It involves more than one from of inheritance namely multilevel, multiple and hierarchal.

All the public and protected members of ‘grand parent’ are inherited into ‘child’ twice, first via ‘parent 1’ and again via ‘parent 2’. This means ‘child’ would have duplicate sets of the members inherited from ‘grand parent’.

The duplication of the inherited members due to these multiple paths can be avoided by making the common base class as virtual class while declaring direct or intermediate base classes.

Multipath inheritance

class A
{
--
--
};
class B1: virtual Public A
{
--
--
};
class B2: public virtual A
{
--
--
};
class C: public B1, public B2
{
--
--
};
//only one copy of A will to inherited
Read More Topics
Static member function in C++
Operator overloading in C++
Overloading binary operators
Overloading unary operators

Santhakumar Raja

Hello The goal of this blog is to keep students informed about developments in the field of education. encourages pupils to improve as writers and readers.

For Feedback - techactive6@gmail.com

Leave a Comment