Que- Make a program for solving diamond problem in hybrid inheritance?
#include<iostream>
using namespace std;
class krishna
{
public:
string name, college;
int age;
long contact;
};
class second: public krishna
{
public:
virtual void getdata ()
{
cout<<"enter your name :- ";
cin>>name;
cout<<"enter your college name :-";
cin>>college ;
cout<<"enter your age:-";
cin>>age;
cout<<"enter your contact number :-";
cin>>contact ;
}
virtual void display ()
{
cout<<"name : "<<name<<endl ;
cout<<"college name : "<<college<<endl ;
cout<<"age : "<<age<<endl ;
cout<<"contact : "<<contact<<endl ;
}
};
class third: virtual public second
{
public:
};
class fourth: public third, virtual public second
{
};
int main ()
{
fourth ob ;
ob.getdata();
ob.display();
return 0;
}
Result:-