I have a 2 by 3 set<set<int> >
named ss
like this:
5 6 7
6 7 8
and I want to remove all 6
's in it and end up like this:
5 7
7 8
I'm trying to do:
for (set<set<int> >::iterator it = ss.begin(); it != ss.end(); it++) {
it->erase(6);
}
which gives me an error:
error: passing ‘const std::set<int>’ as ‘this’ argument of ‘std::set<_Key, _Compare, _Alloc>::size_type std::set<_Key, _Compare, _Alloc>::erase(const key_type&) [with _Key = int, _Compare = std::less<int>, _Alloc = std::allocator<int>, std::set<_Key, _Compare, _Alloc>::size_type = long unsigned int, std::set<_Key, _Compare, _Alloc>::key_type = int]’ discards qualifiers [-fpermissive]
I can compile it by passing -fpermissive
and it seems to be working fine but I was wondering what this error is all about.
EDIT after hyde's suggestion I tried:
for (set<set<int> >::iterator it = ss.begin(); it != ss.end(); it++) {
set<int> temp(*it);
temp.erase(6);
ss.erase(*it);
ss.insert(temp);
}
which seems to be working so I'm guessing sets doesn't allow changing elements as he said..