lundi 23 février 2015

What happens to a pointer that points to an element in a vector when i shuffle it?


I have a std::vector<int> and a pointer int* that points to an element in the vector. Lets say the pointer points to the third element: pointer=&vector.at(2). If I now shuffle the vector, will it still point to the same element (the third) or will it point the the new location where the used-to-third element has moved?


Then I like to make the question a little bit more general: How do pointer and iterators to elements in a vector behave when the vector is expanded, reduced or shuffled?




Aucun commentaire:

Enregistrer un commentaire