How to Store different classes in one array or...

I'm not sure if I phrased the question right, but I'm looking to iterate through an array of similar objects like "projectiles[] and enemies[]"
instead of having them all separate like
"bats[], zombies[], skeletons[], goblins[], etc".

Possibly by storing different classes of the same type in 1 array or an array of their pointers?

That way I can check for collision between enemies and projectiles instead of checking between fireball and zombie, fireball and bat, fireball and skeleton, etc.

Any help would be appreciated!


https://isocpp.org/wiki/faq/virtual-functions#inversion
Use a std::vector of pointers to some base class.
Thanks! Seems to be exactly what I was looking for.
Topic archived. No new replies allowed.