I have a user created struct (named Nze), composed of int x co-ordinate, int y co-ordintate, and int a_value. A series of these structs have been inserted into a vector (named result) which was already sorted and may contain duplicates (the same x and y co-ordinates) If there is a duplicate I want to be able to add the two "duplicate" a_value together in one of the structures and delete the other adjacent one. I tired this code but it is crashing on run time all the time.
Code:
typedef vector<Nze>::iterator vit;
vit it = result.nze.begin()+1;
while (it != result.nze.end() ){
if (equalPosition(*it,*(it-1))) {
(*it).a_value += *(it-1).a_value ;
result.nze.erase(it-1);
}
it++;
}