J
John Black
Hi,
I just found out that in looping the vector, you can not push_back()
to the vector even in some "safe" cases. Here is the code snippet,
vector<pair<UINT32, UINT32> >::iterator itr;
for (itr = vec.begin(); itr< vec.end(); ++itr){
pair<UINT32, UINT32> p1, p2;
... assign value of p1 and p2 ...
if (..in some condition...){
vec.push_back(p1);
vec.push_back(p2);
vec.erase(itr);
return 0;
}
}
I think this is a safe dynamic addition to the vector as you can see
once something is added to the vector, I return from the loop. But from
the debugger I see that after the first push_back(), the iterator, itr,
changes. I just can not image why this happens.
Thanks!
I just found out that in looping the vector, you can not push_back()
to the vector even in some "safe" cases. Here is the code snippet,
vector<pair<UINT32, UINT32> >::iterator itr;
for (itr = vec.begin(); itr< vec.end(); ++itr){
pair<UINT32, UINT32> p1, p2;
... assign value of p1 and p2 ...
if (..in some condition...){
vec.push_back(p1);
vec.push_back(p2);
vec.erase(itr);
return 0;
}
}
I think this is a safe dynamic addition to the vector as you can see
once something is added to the vector, I return from the loop. But from
the debugger I see that after the first push_back(), the iterator, itr,
changes. I just can not image why this happens.
Thanks!