Answer to Question #324104 in C++ for king

Question #324104

Explain the concept of multipath inheritance with the help of suitable programming example.


1
Expert's answer
2022-04-06T17:55:20-0400

Multipath Inheritance in C++ is derivation of a class from other derived classes, which are derived from the same base class.This type of inheritance involves other inheritance like multiple, multilevel, hierarchical etc.


Here is programming example:


#include<iostream>
using namespace std;

class ClassA 
{
  public:
    int a;
};
 
class ClassB : public ClassA 
{
  public:
    int b;
};
 
class ClassC : public ClassA 
{
  public:
    int c;
};
 
class ClassD : public ClassB, public ClassC 
{
  public:
    int d;
};
 
int main()
{
    ClassD obj;
    
    obj.ClassB::a = 10;
    obj.ClassC::a = 100;
    obj.b = 20;
    obj.c = 30;
    obj.d = 40;

    cout << " a from ClassB  : " << obj.ClassB::a;
    cout << "\n a from ClassC  : " << obj.ClassC::a;
    cout << "\n b : " << obj.b;
    cout << "\n c : " << obj.c;
    cout << "\n d : " << obj.d << '\n';

}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS