Virtual Base Class : (Multipath Inheritance)

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

About the author

Santhakumar Raja

Hi, This blog is dedicated to students to stay update in the education industry. Motivates students to become better readers and writers.

View all posts

Leave a Reply