title: C++ : Double free or corruption (out)
body: <p>I'm getting this error</p>
  
  <pre><code>*** Error in `./main': double free or corruption (out): 0x000000000095c8a0 ***
  </code></pre>
  
  <ul>
  <li><code>getPieces()</code> is defined as <code>vector&lt;Piece*&gt; Position::getPieces()</code></li>
  <li><code>getSymbol()</code> returns an <code>int</code></li>
  </ul>
  
  <p>What I want to acheive is to remove from the vector the <code>Piece</code> pointer that is the same as variable <code>Pointer* piece</code>.</p>
  
  <pre><code>int Position::removePiece(Piece* piece) {
    for (size_t i = 0; i &lt; getPieces().size(); i++) {
      if (getPieces()[i] == piece) {
        getPieces().erase(getPieces().begin() + i); // errors happens here
        std::cout &lt;&lt; getPieces().size() &lt;&lt; std::endl;
        return getSymbol();
      }
    }
  
    return -1;
  }
  </code></pre>