Advertisement Jump to content
Sign in to follow this  

Noob STL queue question

This topic is 4903 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I'm fairly proficient with C++ but I have limited experience with the STL. I'm writing something to a spec and I've been told I *must* use the STL queue to store some objects. So far, so good. However, am I right in thinking that I can't traverse the queue without destroying it!? How am I supposed to print it like the spec dictates? I'm confused, especially as it seems there's no std::queue<t>::iterator for me to play with. So, where I'm at now:

    std::cout << (*(incomingPackets.front()));
    std::cout << std::endl;

The second time that's called, it fails an assert after the first object is printed! [bawling] [Edited by - zdlr on August 21, 2005 6:34:47 PM]

Share this post

Link to post
Share on other sites
Double-check whether you've been told to use std::queue or std::deque.
'deque' stands for "double-ended queue", and is traversable.
std::queue is an adaptor, providing a pure queue interface for another container - usually std::deque.

Share this post

Link to post
Share on other sites
The firewall class should store both incoming and outgoing network packets in queue structures

Ignore mentions of 'firewall' and 'network packets' - it's just a firewall simulation that does nothing with real network packets. It's merely an exercise in class design, etc.

I'd be prepared to use a deque if I'd be allowed to iterate over it, it hardly seems mission critical that it uses queue structures exclusively.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!