Multipath Inheritance In C++ Program

In this C++ Inheritance Programs, we will have a look at Multipath Inheritance In C++ Program. Combination of multiple and hierarchical inheritances is called hybrid inheritance. A derived class with two base classes and these two base classes have one common base class is called multipath inheritance

Multipath Inheritance In C++ Program

class A
{
private: //..
public:
    void showdata()
    {
        //...
    }
};
class B: virtual public A //removing ambiguity with virtual base class

{

    //...
};
class C: virtual public A
{
    //..
};
class D: public B, public C
{
public:
    void show_data()
    {
        showdata();//ambiguous which showdata() ?
    }
};

You can learn more about the use of Virtual Base Class in C++.

Leave a Reply

Your email address will not be published. Required fields are marked *

Shopping cart