Removing a pointer from the centre of a vector

Is there a better way to remove something from the middle (well, a general position) of a vector than this:
1
2
3
4
5
6
7
8
9
10
11
void RemoveSprite(int ref){
	delete SpriteList[ref];
	SpriteList[ref] = NULL;
	vector<Sprite*>::iterator i;
	for(i=SpriteList.begin(); i<SpriteList.end(); i++){
		if(*i == NULL){
			SpriteList.erase(i);
			break;
		}
	}
}


Where SpriteList is a global vector of pointers to Sprite?
Last edited on
with vector iterators you should be able of doing this: SpriteList.erase( SpriteList.begin()+ref )

To remove all the elements equal to 0 ( NULL ) you can use remove http://www.cplusplus.com/reference/algorithm/remove/
Oh, I didn't realise you could just add an integer on to the iterator like that.
Thankyou
Topic archived. No new replies allowed.