vector pointer locations guaranteed?

前端 未结 7 1659
无人及你
无人及你 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.

提交回复
热议问题