c++ - Segmentation fault when trying to remove element from a list -


in order solve this problem have, wrote little piece of code:

for (std::list<std::vector<int>>::iterator = l.begin(); != l.end(); ++i) {   (std::list<std::vector<int>>::iterator j = next(i, 1); j != l.end(); ++j) {     if (includes((*j).begin(), (*j).end(), (*i).begin(), (*i).end())) {       l.erase(j++);     }   } } 

the basic idea is, given element of list, remove elements rest of list matches criteria (in case, containment relation).

executing triggers segmentation fault, can't understand. can give me clue this?

the comment right, thanks. corrected code is:

for (std::list<colset>::iterator = l.begin(); != l.end(); ++i) {   std::list<colset>::iterator j = next(i, 1);   while (j != l.end()) {     if (includes((*j).begin(), (*j).end(), (*i).begin(), (*i).end())) {       j = l.erase(j);     }     else {       ++j;     }   } } 

Comments

Popular posts from this blog

mongodb - Struggling to get ordered results from the last retrieved article, given array of elements to search in -

c# - Attribute value in root node of xml Linq to XML -

android - Retrieve value from radioButtons in alertDialog -