A program to demonstrate and resolve problem in multiple inheritance in C++

#include<iostream>
#include<conio.h>
using namespace std;
class Class1
{
protected:
int n;
public:
void setdata1(int a)
{
n=a;
}
};
class Class2
{
protected:
int m;
public:
void setdata2(int a)
{
m=a;
}
};
class Class3: public Class1, public Class2
{
int sum;
public:
void display()
{
sum=n+m;
cout<<“Sum:”<<sum;
}
};
main()
{
int n1, n2;
Class3 c;
cout<<“enter two numbers:”;
cin>>n1>>n2;
c.setdata1(n1);
c.setdata2(n2);
c.display();
getch();
}

Output:

Leave a Reply

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