 <p>The problem is that when more elements are added to a vector it may resize itself. When this happens all elements are moved to a new location and all existing pointers and references to elements get invalidated.</p> <p>There are containers that do not invalidate iterators when new elements are added, such as <code>std::list</code> and <a href="http://bannalia.blogspot.co.uk/2008/09/introducing-stablevector.html" rel="nofollow"><code>boost::stable_vector</code></a>. </p> <p>I.e. <code>boost::stable_vector&lt;Segment&gt;</code> or <code>std::list&lt;Segment&gt;</code> instead of <code>std::stable&lt;Segment&gt;</code> would fix the issue, provided you do not require contiguous storage of <code>Segment</code> elements.</p>