Your problem is that the vector
you are trying to call push_back
on is const
. This is because (since C++11) the elements of a std::set
are accessed through const_iterators
, since changing them might change how they compare and therefore corrupt the set
. To solve that you have two options:
- If
hDisponibles
has no effect on how profesor
compare and it doesn't do to much damage to your overall structure you can declare it mutable
like this: mutable vector<int> hDisponibles;
. mutable
members can be changed even if the structure they reside in is const
- I that is not an option, you have to remove the
profesor
from the set (into a temporary), do your push_back
and reinsert it (be careful about iterator invalidation). Of course this is quite costly.
Your code as posted has an additional bug, since hdisponsibles
is an object, but push_back
is called as if it was a pointer. From your compilermessage it doesn't seem like that bug is in your actual code, but just in case it should be:
(*itP).hDisponibles.push_back(0);
Edit: Found the section in the standard draft (the value type is the same as the key for set
and multiset
: N3290 §23.2.4/6
iterator of an associative container is of the bidirectional iterator
category. For associative containers where the value type is the same
as the key type, both iterator and const_iterator are constant
iterators. It is unspecified whether or not iterator and const_iterator
are the same type. [Note: iterator and const_iterator have identical
semantics in this case, and iterator is convertible to const_iterator.
Users can avoid violating the One Definition Rule by always using
const_iterator in their function parameter lists. —endnote ]