Very good to all:).
I have the following code to check if two objects in a list of pointers to a class Objeto
are in the same position (x, y) and if they are, delete one of them. It works perfectly in Code :: Blocks 17 but in Visual Studio 17 it throws an exception in the line marked with 'EXCEPTION' with the message:
'list iterator not incredable'
and I do not understand why. I'm "forced" to do it in Visual Studio, so I have to fix it. As always if someone can give me a cable I will greatly appreciate it:).
std::list<Objeto*> objetos_;
for (auto Obj = objetos_.begin(); Obj != objetos_.end(); Obj++)
{
for (auto Obj2 = Obj; Obj2 != objetos_.end(); Obj2++) ---> EXCEPCIÓN
{
if ((*Obj)->Get_X() == (*Obj2)->Get_X() && (*Obj)->Get_Y() == (*Obj2)->Get_Y())
{
if ((*Obj)->Get_Nombre() != "USUARIO")
{
delete(*Obj);
Obj = objetos_.erase(Obj);
}
if ((*Obj2)->Get_Nombre() != "USUARIO")
{
delete(*Obj2);
Obj2 = objetos_.erase(Obj2);
}
}
}
}