Write a Cpp program for virtual base class hybrid inheritance?

All QuestionsCategory: Cpp LanguageWrite a Cpp program for virtual base class hybrid inheritance?
Chetan Shidling Staff asked 5 years ago

I need code.

1 Answers
Chetan Shidling Staff answered 5 years ago

Code:

#include <iostream>
using namespace std;
class grandparent
{
public:
void gpfunc()
{
cout<<“gp class function\n”;
}
};
class parent1 : public virtual grandparent
{
public:
void p1func()
{
cout<<“p1 class function\n”;
}
};
class parent2 : public virtual grandparent
{
public:
void p2func()
{
cout<<“p2 class function\n”;
}
};
class child : public parent1, public parent2
{
public:
void chfunc()
{
cout<<“child class function\n”;
}
};
int main()
{
child c;
c.gpfunc();
c.p1func();
c.p2func();
c.chfunc();
return 0;
}