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 {};