I would like to manage a bunch of class objects derived from a common interface class in a shared container.
To illustrate the problem, let's say I create a game in which there will be different actors. Call the IActor interface and get Enemy and Civilian out of it.
Now the idea is for my main game loop to do this:
and
// main loop while(!done) { BOOST_FOREACH(IActor CurrentActor, ActorList) { CurrentActor.Update(); CurrentActor.Draw(); } }
... or something like that. This example obviously won't work, but that is pretty much the reason I'm asking here.
I would like to know: what would be the best, safest and highest level of control for these objects in a common heterogeneous container? I know about various approaches (Boost :: Any, void *, the handler class with boost :: shared_ptr, Boost.Pointer Container, dynamic_cast), but I canβt decide what the path to be here.
I would also like to emphasize that I want to stay away from manual memory management or nested pointers.
Help evaluate :).
c ++ interface containers heterogeneous
Svenstaro
source share