I have a function defined in a superclass, InteractorStyle. Then I have another class that requires that function to be implemented (pure virtual), PointSelector. Then a subclass of PointSelector, PointSelector2D, is instantiated. The compiler complains that I can’t instantiate an abstract class because MyFunction() is not implemented. Why doesn’t the function that gets inherited from InteractorStyle count as this implementation?
#include <iostream>
// I can't change these:
class InteractorStyle
{
void MyFunction(){}
};
class PointSelector
{
virtual void MyFunction() = 0;
};
class PointSelector2D : public InteractorStyle, public PointSelector
{
};
int main()
{
PointSelector2D a;
return 0;
}
Because with multiple inheritance, you have now inherited two unrelated functions, one from each base class. They just so happen to have the same name as each other (in fact, they don’t; one is called
InteractorStyle::MyFunction, the other is calledPointSelector::MyFunction).But one does not override the other (at least, not in the sense that you are hoping for).