Are vector pointers affected by resize()?

Say I have a pointer to a vector:

1
2
3
vector<int> * p;
vector<int> myvec;
p = &myvec;


And I now resize my vector:

myvec.resize(50); // cause reallocation of memory

my vector has now moved elsewhere in memory right? So is the pointer p still valid? I now that iterators become invalid, but what about pointers to the vector itself? If not, why? Hasn't the vector moved in memory?
my vector has now moved elsewhere in memory right?

The vector itself hasn't. Its underlying array, starting at &myVec[0], could potentially move if the resize cannot get a contiguous chunk of memory at its current location.

So is the pointer p still valid?
&myVec is still valid; &myVec[0] may have changed.

but what about pointers to the vector itself? If not, why? Hasn't the vector moved in memory?

These questions were answered above.
Last edited on
Great, thanks for this; I know it's simple but I couldn't find that anywhere.
Can't touch this
ne555 wrote:
Can't touch this

Obligatory link: http://www.youtube.com/watch?v=otCpCn0l4Wo&ob=av3e
Last edited on
Topic archived. No new replies allowed.