I am trying to design something that doesn't rely on casting. I asked a question here and I believe ultimately there is a better way, so I'm asking for advice.
I have a generic Object
of which there will be subclasses.
I have generic Node
objects which contain as a member a pointer to an Object
. Node
s can be subclassed to offer more specific behaviour about how to handle their Object
as well as to set what type of subclassed Object
that particular node is using.
The problem is that my base class requires as a member Object * myObject
so that my app can traverse all the Node
s and call a draw
function on all the myObject
s.
But how to handle the situation of a subclassed Node calling custom functions on a subclassed Object? These functions could be truly unique and have no place in a base class.
One option I considered is for the subclass to store its pointer member as MyObjectSubclass * myObject
but a subclass cannot override a base class member, right? So that doesn't really work.
I'd appreciate a more experienced advice for this type of design.