I’m making a game where pretty much everything inherits from Entity. I also have an IRenderable interface for all entities that need to be rendered.
When loading the level, every entity that is IRenderable is placed in a vector of IRenderable* which is then passed to the renderer.
When I instance any Entity, I add it to a vector of Entity* .
What I’m wondering is what exactly should I do when this entity sends an ENTITY_DESTROYED message?
The problem is that I do not know if this Entity is IRenderable. I’d have to try and cast it for that and I’m not sure if casting is a good idea here.
What else could I do to avoid casting?
Thanks
Another point to note, even if I know it is IRenderable, the pointer might be different due to multiple inheritance.
This article is the best discussion which I’ve found on the subject. I recommend it.
Otherwise, this may be useful.
I’d call this solution a band-aid.