vector pointer locations guaranteed?

前端 未结 7 1661
无人及你
无人及你 2021-01-05 01:05

Suppose I have a vector of ints,

std::vector numbers;

that is populated with a bunch of values, then I say do this (where an ent

相关标签:
7条回答
  • 2021-01-05 01:40

    Your paranoia is correct. Resizing a std::vector can cause its memory location to change. That means your oneNumber is now pointing to an old memory location that has been freed, and so accessing it is undefined behavior.

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