I’m trying to do a simple erase and keep getting errors.
Here is the snippet of code for my erase:
std::list<Mine*>::iterator iterMines = mines.begin(); for(int i = oldSizeOfMines; i >0 ; i--, iterMines++) { if(player->distanceFrom(*iterMines) < radiusOfOnScreen) { onScreen.push_back(*iterMines); iterMines = onScreen.erase(iterMines); iterMines--; } }
I keep getting a compiler message:
1>c:\users\owner\desktop\bosconian\code\bosconian\environment.cpp(158) : error C2664: 'std::list<_Ty>::_Iterator<_Secure_validation> std::list<_Ty>::erase(std::list<_Ty>::_Iterator<_Secure_validation>)' : cannot convert parameter 1 from 'std::list<_Ty>::_Iterator<_Secure_validation>' to 'std::list<_Ty>::_Iterator<_Secure_validation>' 1> with 1> [ 1> _Ty=SpaceObject *, 1> _Secure_validation=true 1> ] 1> and 1> [ 1> _Ty=Mine *, 1> _Secure_validation=true 1> ] 1> and 1> [ 1> _Ty=SpaceObject *, 1> _Secure_validation=true 1> ] 1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
I’m puzzled because I believe I’m giving it the correct iterator.
Mine is a subclass of SpaceObject (a second generation subclass that is)
Does this have anything to do with it? And how would I fix it?
The problem is you are trying to use the iterator of mines as an iterator in the onScreen list. This will not work.
Did you mean to call mines.erase(iterMines) instead of onScreen.erase(iterMines)?