The below code works during release mode and raising an error at g_ItemList.push_back() during debug mode only, I went through few SO posts and forums. Somebody mentioned "You can't iterate through a vector while pushing back, as push_back may invalidate iterators". But it's not clear for me. Could somebody explain the logic behind it and How to fix this? I am using Visual Studio 2010 (v100) to compile the program
std::vector<class PPart> VECT_ITEMS;
VECT_ITEMS g_ItemList;
g_ItemList.clear();
for (i = 0; i < n; i++)
g_ItemList.push_back (temp[i]); //where PPart *temp;