title: c++ debug assertion failed
body: <p>I have a problem when I try to run this code</p>
  
  <pre><code>void MyClass::setUp(){
      list-&gt;clear();
      Iterator i = ctr.getAll().iterator();
      while (i.valid()) {
          list-&gt;addItem(QString::fromStdString(i.elem().getNr()));
          i.next();
      }
  }
  </code></pre>
  
  <p>When I exit the function an error occurs:</p>
  
  <blockquote>
    <p>Debug Assertion Failed!</p>
    
    <p>File:C:\Program Files \Microsoft Visual Studio 14.0\ VC\ include\
    xmemory0 line:106</p>
    
    <p>Expression: "(_Ptr_user&amp;(_BIG_ALLOCATION_ALIGNMENT -1))==0 " &amp;&amp;0</p>
  </blockquote>
  
  <p>I am trying to iterate through a custom list </p>
  
  <p>The Iterator class is this:</p>
  
  <pre><code>void Iterator::first(){
      while (pos &lt; ht.nrElem &amp;&amp; ht.list[pos] == nullptr)
          pos++;
      if (pos &lt; ht.nrElem)
          current = ht.list[pos];
  }
  
  Iterator::Iterator(const HashTable &amp; ht): ht { ht }{
      pos = 0;
      first(); // current will refer the first element of the list
  }
  
  
  void Iterator::next(){
      current = current-&gt;getNext();
      if (current == nullptr) {
          pos++;
          first();
      }
  }
  
  bool Iterator::valid(){
      return (pos &lt; ht.nrElem) &amp;&amp; (current != nullptr);
  }
  
  Car&amp; Iterator::elem() const{
      return current-&gt;getCar();
  }
  </code></pre>