Home c++ Virtual inheritance in C++

Virtual inheritance in C++

Author

Date

Category

What is it and why are it used in C++?


Answer 1, Authority 100%

Virtual inheritance is necessary in such a situation.

class a {int a; };
Class B: Public A {};
Class C: Public A {};
Class D: Public B, Public C {};

In the D class, in this case, there will be two fields named a and they both will belong to the class a .
The problem is to determine which variable is the appeal. To exclude such a situation use virtual inheritance. Correct announcement in this example will be

class a {int a; };
Class B: Public Virtual A {};
Class C: Public Virtual A {};
Class D: Public B, Public C {};

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions