0

无法修改地图中的队列。

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();
    }
}

但我一直收到一个错误告诉我:

错误:将 'const std::queue > >' 作为 'std::queue > >& std::queue > >::operator=(const std::queue > >&)' 的 'this' 参数传递会丢弃限定符

提前感谢您对此提供的任何帮助。:-(

4

1 回答 1

3

您正在通过 a 访问地图元素const_iterator,因此您无法修改它们(严格来说,您只能const在元素上调用方法,而std::queue::pop()不是一个)。尝试使用非常量iterator

map<string, queue<item*> >::iterator itr;
于 2013-01-31T07:13:59.047 回答