tezromania
tezromania

Reputation: 817

modifying a queue in a map

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. :-(

Upvotes: 0

Views: 91

Answers (1)

juanchopanza
juanchopanza

Reputation: 227418

You are accessing the map elements via a const_iterator, so you cannot modify them (strictly speaking, you can only call const methods on the elements, and std::queue::pop() isn't one). Try using a non-const iterator instead:

map<string, queue<item*> >::iterator itr;

Upvotes: 3

Related Questions