Reset iterator inside loop with erase method
<p>Here's a little piece of code, which is making us a little mad...</p>

<pre><code>for (vector&lt;QSharedPointer&lt;Mine&gt;&gt;::iterator itMine = _mines.begin(); 
       itMine != _mines.end();) {
    auto point2 = shipFire[l].getBulletLine().p2();
    if (_mines[pos]-&gt;checkCollision(point2)) { // _mines is a Vector&lt;QSharedPointer&lt;Mine&gt;&gt;
        Explosion explosionMine(_mines[pos]-&gt;point());
        _explosions.push_back(explosionMine);
        itMine = _mines.erase(itMine);
        bulletErased = true;
        scoreFrame += 100;
    }
    else {
        ++itMine;
        pos++;
    }
}
</code></pre>

<p>Here is the problem, the <code>itMine</code> is erasing two of our <code>vector&lt;..&lt;Mine&gt;&gt;</code> and it's making the program to shutdown unexpectedly</p>

<p>We thought about it, and came up with this : All of our iterators are being invalidated after erasing the one of the Mine, right ?</p>

<p>But we are a little confused about how to change our actual code to fit to the new one ?</p>

<p>The main question is : how do we reset this itr ? </p>

<p>ps : if you have any questions, or if you need a little more of code to understand the logic behind, feel free to ask more question !</p>

<p>Best Regards, and thank you in advance.</p>