does a pointer to an element of a vector remain after adding to or removing from the vector (in c++)

前端 未结 1 786
难免孤独
难免孤独 2021-01-23 02:23

I\'m working on a collision engine and more specifically, I am trying to make a vector of relevant bodies in the world. To be able to access a specific body in the vector of bod

相关标签:
1条回答
  • 2021-01-23 03:06

    After removing an element in a vector all elements after the removed element will be moved one position left. So either the pointer will point to some other element or to the deleted element if it was the last element in the vector.

    If you add a new element then the vector can reallocate memory. So all pointers to the elements of the vector will be invalid.

    0 讨论(0)
提交回复
热议问题