修改映射中的队列
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();
}
}
但是我一直收到一个错误,告诉我:
错误:将"const std::queue>>"作为"std::queue>>&std::queue>>::operator=(const std::queue>>&)"的"this"参数传递丢弃限定符
提前感谢您对此的任何帮助。
您是通过 const_iterator
访问 map 元素的,因此您无法修改它们(严格来说,您只能在元素上调用const
方法,std::queue::pop()
不是一个)。请尝试改用非常量iterator
:
map<string, queue<item*> >::iterator itr;
相关文章:
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- boost::进程间消息队列引发错误
- 如果我只是不访问queue_front节点的子节点,而是将它们推到队列中呢?还是BFS吗
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- 将函数类成员映射到类本身内部
- 如何在 C# 中映射双 C 结构指针?
- 如何在C++中使用结构生成映射
- 使用std::函数映射对象方法
- 如何加载(或映射)文件部分的最大大小,但适合在Windows上的RAM
- Android NDK传感器向事件队列报告奇怪的间隔
- C++映射分割错误(核心转储)
- 内联映射初始化的动态atexit析构函数崩溃
- 使用"std::unordereded_map"映射到"std::list"对象
- C++优先级队列,按对象的唯一指针的特定方法升序排列
- C++:使用队列作为映射的值
- 映射类型为的队列容器
- 并发队列+映射在c++中的实现
- 无法推送到由静态映射<结构创建的队列,队列>
- 修改映射中的队列
- 优先队列映射