Having trouble modifying a queue in a map.
map<string , queue<item*> > itemList; // what the map creation looks like
map<string, queue<item*> >::const_iterator itr; // creating an iterator
//for every item in a warehouse
for(itr = itemList.begin(); itr != itemList.end(); ++itr)
{
//while there are items in the queue with 1 day shelf life
while(itr->second.front()->getLife() == 1)
{
//throw them away
itr->second.pop();
}
}
but i keep getting an error telling me this:
error: passing ‘const std::queue > >’ as ‘this’ argument of ‘std::queue > >& std::queue > >::operator=(const std::queue > >&)’ discards qualifiers
thanks in advance for any help on this one. 🙁
You are accessing the map elements via a
const_iterator, so you cannot modify them (strictly speaking, you can only callconstmethods on the elements, andstd::queue::pop()isn’t one). Try using a non-constiteratorinstead: