queues are implemented as containers adaptors, which are classes that use an encapsulated object of a specific container class as its underlying container, providing a specific set of member functions to access it elements. Elements are pushed into the "back" of the specific container and popped from its "front".
存储迭代器时应该非常小心。 修改集合很容易使所有迭代器失效。 你最好存储一个 id 或一个(托管)指针。
You should be very careful about storing iterators. Modifying the collection can easily invalidate all iterators. You would be far better storing an id or a (managed) pointer.
发布评论
评论(2)
如果您使用
deque
而不是queue
,则此方法有效。Queue
不是一个容器,而是一个外观,因此它不支持::iterator
调用。来自 cplusplus.com:
This works if you use a
deque
instead of aqueue
.Queue
is not a container, but a facade so it does not support the::iterator
call.From cplusplus.com:
存储迭代器时应该非常小心。 修改集合很容易使所有迭代器失效。 你最好存储一个 id 或一个(托管)指针。
You should be very careful about storing iterators. Modifying the collection can easily invalidate all iterators. You would be far better storing an id or a (managed) pointer.