Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stl queue simple problem 1

Status
Not open for further replies.

Tdrgabi

Programmer
Jun 24, 2004
43
RO
hi a have an stl queue object in my program.

i can use any functions in the queue but i cant seem to use "top()" ... it gives me that top() is not a member of queue.

I looked in help and top is in queue ... is there a different way to write something like something=queueObj.top(); .... ?
 
ps. top doesn't really make sense for a queue.. it does for a stack. if you think of it in english, front seems to make more sense.. if you look on msdn, it looks like it just peeks at teh element at the front of the queue (i assume this is what you mean by top).. also to remove an element you could probably use pop.. (i think this is a badly chosen name as pop really applies to a stack more than a queue).
 
yes i was looking for front ... but i always used to call it top ... never heard of front in a queue .... thanks, it works now.
 
no problem! but i think the queue functions are really badly named (front is ok tho!) because you don't pop/push from a queue! you queue, deque or add/remove!
 
I'm running Visual C++ 6.0 and I have a top() function in the STL queue class. :)
 
The C++ Standard defines top() member for priority_queue class template (its implementation is the same as for queue::front()). There is only front() member in STL queue class template.
There is (non-standard!) queue::top() member in VC++ 6.0 <queue>. Don't use it.
 
oh well.. as i said, i haven't used this before... i just saw the post and looked up msdn!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top