Hi there,
I have the following toy code, intended to remove duplicates from a vector:
void overlap_removal(vector<int> &vec1, vector<int> &vec2) {
for (vector<int>::iterator it1 = vec1.begin(); it1 != vec1.end(); ++it1) {
for (vector<int>::iterator it2 = vec2.begin(); it2 != vec2.end(); ++it2) {
if ((*it1)*(*it2) < 10) {
vec1.erase();
}
}
}
}
I'm doing a slightly more complicated comparison in the real code, but didn't want to confuse matters. The problem is the segmentation fault that inevitably follows the execution of this: I think this is due to the fact that I'm deleting an element and then continuing to loop over the same vector.
How can I make the code work? Is this even the right starting point? Thanks in advance