Function to remove item from vector

I'm trying to find an efficient way to remove an object from a vector without leaving a hole. The documentation I've read has been a little obtuse for saying how to do this, but this is what I have so far:

1
2
3
4
5
6
7
8
bool kill(Character * c, vector<Character*> * chVec){
	for(vector<Character*>::iterator it = chVec->begin(); it < (chVec->end()); it++){
		if(c->getID() == chVec->at(ITERATION_LOCATION)->getID()){//Check ID at iteration location?
			chVec->erase(it);
		}
	}
	return true;
}


My first question is how to reference the index that the iterator is currently at (see line 3), as simply using 'it' as an argument is not valid. My second question is if the rest of the logic and syntax is appropriate, or if I should use push_back and pop_back to avoid having a hole.
Last edited on
Erase doesn't leave a hole in vectors. I would try and pass that vector by reference instead of as a pointer to make things easier while still being efficient.
Last edited on
How would I use remove in this situation? I understand how it works with a primitive type, but how would I have it remove based on the value of a member of an object in the vector.
Topic archived. No new replies allowed.