I'm trying to do something like the following:
myvec is a vector of Couple objects (formed each with an EntityA and an EntityB). I'm trying to remove the duplicate couples.. Anyway sometimes the following code crashes with an out of bound it2. The condition is fine, the iterators seems not
if(myvec.size()>1)
for(vector<Couple>::iterator it1 = myvec.begin(); it1+1 !=myvec.end();){
for(vector<Couple>::iterator it2 = it1+1; it2 !=myvec.end();){
if((it1->EntityA!=it2->EntityA&&it1->EntityA!=it2->EntityB)||
(it1->EntityB!=it2->EntityA&&it1->EntityB!=it2->EntityB)){
it2++;
}
else{
myvec.erase(it2);
}
}
it1++;
}
Any solution/alternative?