The obvious solution is to create a combined interface:
class IAB : public virtual IA, public virtual IB
{
};
, have your AB1
and AB2
derive from it (in addition to their
current derivations), and keep IAB*
in the vector.
This means that B1
and B2
must also derive virtually from
IB
; given the direction things seem to be going, A
should
probably also derive virtually from IA
.
There are strong arguments that inheritance of an interface should always be virtual. Without going that far: if a class is designed to be derived from, and it has bases, those bases should be virtual (and arguably, if a class is not designed to be derived from, you shouldn't derive from it). In your case, you're using the classic mixin technique, and generally, the simplest solution is for all inheritance in a mixin to be virtual.