Would the following code still be negatively affected by the lack of virtual inheritance?
If so, would the negative effects be the same as (or as bad as) the negative effects of multiple inheritance without virtual inheritance if class A
did contain data members?
class A
{
public :
virtual ~A ( ) { }
virtual int foo ( ) const = 0 ;
} ;
class B : public A
{
public :
virtual ~B ( ) { }
} ;
class C : public A
{
public :
virtual ~C ( ) { }
} ;
class D : public B , public C
{
public :
virtual int foo ( ) const { return 12 ; }
} ;
Assuming that you want to use
A
as a general interface, if you don't make the inheritance virtual you wouldn't be able to do something like this, because there are two inheritance paths to the base classA
from the childD
:If you don't need to use a
D
as anA
then (A) Why do you have it as an abstract base in the first place and (B) No, there is no need for the inheritance to be virtual.