I am getting this error when trying to iterate over a map that is pointed to by another object. It works when I am not using a pointer. (Iterating over the member map “pieces”) I am therefore wondering what to do, or if it’s not possible to iterate through the map like this ? :
Board * Board::ccBoard(){
Board * newBoard = new Board();
map<Vec2, Piece>::iterator it;
for (it = newBoard->pieces.begin(); it != newBoard->pieces.end(); ++it)
newBoard->removePiece(it->first);
return newBoard;
}
Thanks in advance!
The
removePiece()function removes the element thatitis referring to, invalidatingit. An attempt is then made to incrementitresulting in the assertion failure. Frommap::erase():I am unsure what the intention of the
forloop is, it appears that it would effectively empty themapin which case just usemap::clear():