C++ Pitfalls 之 reference to an object in a dynamically allocated containter

(留坑待填)

 Extraction from the C++ Programming Language 4th. ed., Bjarne Stroustrup

31.3.3 Size and Capacity

The size is the number of elements in the container; the capacity is the number of elements that a container can hold before allocating more memory.

When changing the size or the capacity, the elements may be moved to new locations. That implies that iterators (and pointers and references) to elements may become invalid (i.e., point to the old element locations).

原文地址:https://www.cnblogs.com/Patt/p/5819940.html