Monday, 26 April 2021

Inherit a class virtually in C++

 #include<iostream.h>

#include<conio.h>

class A

{

public:

 A()

 {

 cout<<"C-A"<<endl;

 }


};

class B

{

public:

B()

{

cout<<"C-B"<<endl;

}


};


class C:  A, virtual B

{

public:

C()

{

cout<<"C-C"<<endl;

}


};



int main()

{

clrscr();

C ob;


getch();

return 0;


}


Output:

C-B

C-A

C-C

No comments:

Post a Comment