I'm building my first game using C++ and SDL.
I have a SpriteGroup object that contains a vector of pointers of my Sprites :
std::vector <Sprite*> m_sprites;
Everytime I want to create a sprite I create the object as normal and add it's pointer to this vector e.g.
Sprite* enemy = new Enemy ();
m_sprites.push_back( enemy );
(It's a little more complicated than this, but this is the pertinent code).
And my update function in my main loop will loop through this vector and call the update function of each object in the vector (and all of the rest of the stuff that needs doing).
When one of these objects goes out-of-bounds I want to remove it. I have functions which identifies when this occurs and calls a delete function. This finds the position in the vector of the object I want to remove and erases it :
void SpriteGroup::remove( int spriteID ) {