title: Strange problem with vectors
body: <p>I have a really strange problem with stl vectors in which the wrong destructor is called for the right object when I call the erase method if that makes any sense.<br>
  My code looks something like this:<br></p>
  
  <pre><code> for(vector&lt;Category&gt;::iterator iter = this-&gt;children.begin(); iter != this-&gt;children.end(); iter++)
      {
          if((*iter).item == item)
          {
              this-&gt;children.erase(iter);
              return;
          }
          -------------------------
      }
  </code></pre>
  
  <p>It's just a simple function that finds the element in the vector which has some item to be searched, and removes said element from the vector. My problem is than when the erase function is called, and thus the object which the iterator is pointing at is being destroyed, the wrong destructor is being called. More specific the destructor of the last element in the vector is being called, and not of the actual object being removed. Thus the memory is being removed from the wrong object, which will still be an element in the vector, and the actual object which is removed from the vector, still has all of it's memory intact.<br>
  The costructor of the object looks like this:</p>
  
  <pre><code>Category::Category(const Category &amp;from)
  {
      this-&gt;name = from.name;
      for(vector&lt;Category&gt;::const_iterator iter = from.children.begin(); iter != from.children.end(); iter++)
          this-&gt;children.push_back((*iter));
  
      this-&gt;item = new QTreeWidgetItem;
  }
  </code></pre>
  
  <p>And the destructor</p>
  
  <pre><code>Category::~Category()
  {
      this-&gt;children.clear();
      if(this-&gt;item != NULL)
      {
          QTreeWidgetItem* parent = this-&gt;item-&gt;parent();
          if(parent != NULL) parent-&gt;removeChild(this-&gt;item);
          delete this-&gt;item;
      }
  }
  </code></pre>