When vector needs more memory it will reallocate memory somewhere, I don\'t know where yet! and then pointers become invalid, is there any good explanation on this?
When you add or remove items from a vector
, all iterators (and pointers) to items within it are invalidated. If you need to store a pointer to an item in a vector, then make the vector const
, or use a different container.
It shouldn't matter to you where the vector stores things. You don't need to do anything, just let it do its job.