struct InterfaceA
{
virtual void fn() = 0;
};
class ClassA
{
public:
void fn() { }
};
class ClassB :
public ClassA,
public InterfaceA
{
};
I expected that this would work, however, I get the following:
1>****(38) : error C2259: 'ClassB' : cannot instantiate abstract class
1> due to following members:
1> 'void InterfaceA::fn(void)' : is abstract
1> ****(19) : see declaration of 'InterfaceA::fn'
I know that I could include something in class B like
void fn() { ClassA::fn(); }
but at that point I might as well just use composition rather than inheritance. While in general I'm a huge fan of composition, I wanted to use inheritance so that the "ClassB" classes have only the unique code in them (would make the code pleasant to read.) Is there a way to make ClassB automatically use the method in ClassA to satisfy InterfaceA?
My question is exactly the same as http://stackoverflow...-abstract-inter, but I didn't see a real "solution" to my question of not having to add a proxy function. Also, if there is a good reason why this is not possible for a compiler to figure out, or why you wouldn't want this behavior, I'd love to know.