title: C++ Segmentation when using erase on std::list
body: <p>I'm trying to remove items from a C++ linked list using <code>erase</code> and a list iterator:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;list&gt;
  
  class Item
  {
    public:
      Item() {}
      ~Item() {}
  };
  
  typedef std::list&lt;Item&gt; list_item_t;
  
  
  int main(int argc, const char *argv[])
  {
  
    // create a list and add items
    list_item_t newlist;
    for ( int i = 0 ; i &lt; 10 ; ++i )
    {
      Item temp;
      newlist.push_back(temp);
      std::cout &lt;&lt; "added item #" &lt;&lt; i &lt;&lt; std::endl;
    }
  
    // delete some items
    int count = 0;
    list_item_t::iterator it;
  
    for ( it = newlist.begin(); count &lt; 5 ; ++it )
    {
      std::cout &lt;&lt; "round #" &lt;&lt; count &lt;&lt; std::endl;
      newlist.erase( it );
      ++count;
    }
    return 0;
  }
  </code></pre>
  
  <p>I get this output and can't seem to trace the reason:</p>
  
  <pre><code>added item #0
  added item #1
  added item #2
  added item #3
  added item #4
  added item #5
  added item #6
  added item #7
  added item #8
  added item #9
  round #0
  round #1
  Segmentation fault
  </code></pre>
  
  <p>I'm probably doing it wrong, but would appreciate help anyway. thanks.</p>