virtual inheritance

Virtual inheritance is used in C++.
It is a technique in which we can create only one copy of the base class object though it is present in other classes of the hierarchy. This is mainly useful in Multiple inheritance.
When you have a class (class A) which inherits from 2 parents (B and C), both of which share a parent (class D). If you don’t use virtual inheritance in this case, you will get two copies of D in class A: one from B and one from C. To fix this you need to change the declarations of classes C and B to be virtual.
```
#include <iostream>
using namespace std;

class A {
public:    
    A() { cout << "A" << endl; }
};
class B : virtual public A {
public:    
    B() { cout << "B" << endl; }
};
class C : virtual public A {
public:    
    C() { cout << "C" << endl; }
};
class D : public B, C {
public:
    D() { cout << "D" << endl; }
};

int main() {
    D d;
    return 0;
}
```