How to insert a new node vector into a vector, change the value of the data link of the first node? !!
Because the elements of the vector are stored in an adjacent array. When there is more space in the array, all elements are moved to a larger one, invalidating all iterators, pointers, and references to them.
I assume that std :: vector might shuffle some memory, but should this not change the correctness of the link ??
Sure. A link refers to a specific object at a specific address; it does not track an object if it moves.
If you need stable links, use deque ; or (if possible) use reserve to set the vector capacity large enough to contain anything you could add. Links are invalid only when redistribution is necessary, and this only happens when you try to go beyond the current capacity.
Alternatively, you can save the index of the object, not a link to it.
source share