Write a program of virtual base class


 

/* Write a program of  virtual base class*/

#include<iostream.h>

#include<conio.h>

class grandparent

{

public:

void dis()

{

cout<<“thisis grandparent”<<endl;

}

};

class parent1:virtual public grandparent

{

public:

void dis1()

{

cout<<“this is parent1 class”<<endl;

}

};

class parent2:virtual public grandparent

{

public:

void dis2()

{

cout<<“this is parent2 class”<<endl;

}

};

class child:public parent1,public parent2

{

public:

void dis3()

{

cout<<“this is parent3 class”<<endl;

}

};

void main()

{

child c1;

clrscr();

c1.dis();

c1.dis1();

c1.dis2();

c1.dis3();

getch();

}

/*output:

this is grandparent

this is parent1 class

this is parent2 class

this is parent3 class*/

Related Posts

Comments are closed.