I understand and have read enough about the diamond problem which is solved by virtual inheritance. My question here is
"What does placing virtual next to a base class that you would be inheriting from actually mean"
class A { public: void Foo() {} };
class B : virtual public A {};
class C : virtual public A {};
class D : public B, public C {};
I wanted to know if my understanding is correct. In the statement
class D : public B, public C {}
The compiler will go over first base class B and notice that its inheriting virtually from class A
. The compiler will check if instance of class A is present if not it will create an instance of A that is derived by B . The compiler will then go over class C and notice that it inherits virtually from class A. However since its being inherited virtually by C and an instance of A is already present it wont include a new instance. Thus solving the diamond problem. Is this understanding correct ?