Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If your <code>mother</code> pointers point directly to elements of the <code>pieces</code> vector you will get in all kinds of trouble.</p> <p>Deleting an element from <code>pieces</code> will shift all the positions of the elements at higher indexes. Even inserting elements can make all the pointers invalid, since the vector might need to reallocate it's internal array which might transfer all the elements to new positions in memory.</p> <p>To answer your main question: You can't delete the element you have the pointer to directly, you would first need search through the vector to find it, or calculate it's index in the vector.</p> <p>Not storing pointers into <code>pieces</code> as <code>mother</code> but instead the indexes of the elements would make it a bit more robust, so that at least inserting new elements could not break the existing <code>mother</code>s. But deleting from <code>pieces</code> would still shift elements to new indexes.</p> <p>Using a <a href="http://www.cplusplus.com/reference/stl/list/" rel="nofollow noreferrer"><code>std::list</code></a> for <code>pieces</code> and storing iterators into that as <code>mother</code> might be a solution. Iterators of <code>std::list</code> are not invalidated if other elements are of that list are removed/added. If different elements can have the same <code>mother</code> you still have a problem finding out when to remove the <code>mother</code> elements, than maybe using <a href="http://www.boost.org/doc/libs/release/libs/smart_ptr/shared_ptr.htm" rel="nofollow noreferrer"><code>boost::shared_ptr</code></a> would be simpler.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload