If a base class is both ``++virtual++`` and non-virtual in a multiple inheritance hierarchy then there will be at least two copies of the base class sub-object in the derived object. This may not be consistent with developer expectations.


== Noncompliant Code Example

----
class A {};
class B1: public virtual A {};
class B2: public virtual A {};
class B3: public A {};
class C: public B1, B2, B3 {}; // Noncompliant, A is both virtual (through B1 and B2) and non-virtual (through B3)
----


== Compliant Solution

----
class A {};
class B1: public virtual A {};
class B2: public virtual A {};
class B3: public virtual A {};
class C: public B1, B2, B3 {}; // Compliant, A is always virtual
----


== See

* MISRA {cpp}:2008, 10-1-3 - An accessible base class shall not be both virtual and non-virtual in the same hierarchy.


ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)

include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]
