I worry that you declared these variables as global:

vector<plane> planes;
vector<plane>::iterator planeIterator;

I hope you only wanted to make this code snippet as small as possible. If you...