On 26.02.2016 17:41,
jomar...@hotmail.com wrote:
> Hi,
>
> I'm using a few shared pointers to a large vector that might be resized (pointers to the vector itself, not to individual elements). My question is: Do all the shared pointers still point to the vector after it is resized? Thus far, it seems that they do with g++ version 5.2.0. However, for portability I'd like to know what the standard says.
std::vector consists of the std::vector object itself and of a separate
resizable buffer containing the elements. Once created, the std::vector
object stays at the same location in memory (an object in C++ *is* an
area of memory) until it is destroyed, so any smart or non-smart
pointers to it remain valid during its lifetime.
With the elements in the resizable buffer the things are different,
their location can change during operations like resizing, so the
pointers and references to the elements can become invalid - but you
already know that.
hth
Paavo