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

を介してマップ要素にアクセスしているため、const_iteratorそれらを変更することはできません (厳密に言えば、const要素のメソッドのみを呼び出すことができ、 std::queue::pop()1 つではありません)。iterator代わりに非 const を使用してみてください。

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