I think wrapping the class would be the simplest option. Rather than directly inheriting from RefCounter create an intermediary class.
struct RefCounterVirtPrivate_
{
int count;
RefCounterVirt()
: count( 0 )
{ }
};
struct RefCounter : public virtual RefCounterVirtPrivate_
{
};
struct A : public RefCounter { };
struct B : public RefCounter { };
struct C : public A, public B { };
Then everything can inherit from RefCounter
without any need to care about virtual inheritence. You don't even have to change any existing code -- virtual inheritence of RefCounter
itself should be harmless.
This of course doesn't guarantee people don't inherit from RefCounterVirtPrivate_
directly, but that is why I've given it an obvious name. It's harder to accidentally do this than forget a virtual
keyword.