Similar to this question but with objects instead of pointers.
If I have the following code
Foo f;
vector<Foo> vect;
vect.push_back(f);
vect.erase(vect.begin());
Where does my object go? Is delete called on it? What if someone else holds a pointer to it? Is this a memory leak?
push_backstores a copy offin the vector, anderasedestroys it.fitself is not affected by that.All pointers, references and iterators to an element in a vector are invalidated when you
eraseit. Using them to access the element aftereraseyields undefined behavior.