The fact that you are storing the different objects as members of the class shouldn't prevent you from storing pointers to them in the IRenderable*
vector.
struct GameState {
Ball ball;
Bonus bonus;
vector<IRenderable*> m_items;
GameState() // constructor
{
m_items.push_back(&ball);
m_items.push_back(&bonus);
}
};
This way you also don't have to worry about freeing the pointers in m_items
. They will be automatically destroyed when the GameState
is destroyed.
Also, your syntax of foreach is funky.