So, I have this polymorphic hierarchy:
ClassA
Is not abstract, no pure virtual functions, but a few virtual functions
ClassB:public ClassA
Defines an extended interface for a certain type of subclass;
is abstract with pure virtual functions
ClassC:public ClassB
Usable class, no more subclassing
Here's the deal, I will have objects of ClassA
and ClassC
thrown together into containers and iterated through. To perform this iteration, a non-pure virtual function is present in ClassA
but is empty with just {}
; that is, it is empty, made available only if the iteration encounters a ClassC
in which case it is invoked, otherwise it does nothing. I can't have it be pure otherwise I cannot have objects of ClassA
.
But to ensure that ClassC
does in fact implement that function, forcing the user of that class to do so, I make this function pure virtual in ClassB
.
Is this acceptable? Nothing will "break" if I take a non-pure virtual function, make it pure, then make it non-pure again in ClassC
?