Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li><p>Think of the requirements of the addresses of items in a linked-list (<code>list</code>). They don't need to be sequential in memory.</p></li> <li><p><code>delete</code> is something that's manually done on pointers, it wouldn't happen automatically (even if the pointer goes out of scope) (unless done in some API). Iterators are (generally) classes, so <code>delete</code> would not even apply. The iterator would get destructed though.</p> <p>You can also probably classify a pointer as an iterator. But <code>delete</code> will still not be called automatically.</p></li> <li><p>Note that <a href="http://www.cplusplus.com/reference/iterator/" rel="nofollow">this only applies to random access iterators</a>. You can calculate the number of items in a container as follows:</p> <pre><code>int count = 0; for (iterator it = begin(); it != end(); ++it, ++count) { } </code></pre> <p>so you increment <code>begin()</code> <code>count</code> times to get to <code>end()</code>,<br> so <code>begin() + count = end()</code>,<br> so <code>end() - begin() = count</code>, and <code>count = size()</code>,<br> so <code>end() - begin() = size()</code></p></li> <li><p>This is not the way C++ works. Although there are design patterns to achieve this behaviour, usually when modifying a class, it's your responsibility to ensure any dependent classes are updated if invalidated. When you'd try to use an iterator of a container that went out of scope, this would result in undefined behaviour.</p></li> <li><p><code>end()</code> is past the last element, probably with something like this in mind: (I'm sure among other reasons)</p> <pre><code>for (iterator it = begin(); it != end(); ++it) </code></pre></li> </ol>
    singulars
    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.
    3. 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