There is a function to get an element, another to remove it:
typedef queue<MyClass> MyQueue; MyQueue q; q.push(MyClass(42));
Rationale: If there was only one pop function that returns the front element, it would be impossible to get a reference to the front element, since it would be removed from the queue. If you just want to read a huge element before discarding it, you certainly do not want your code to execute a copy.
EDIT: Another fundamental reason is that having two functions means that the user is responsible for making the copy. Suppose there is only one pop function: what happens if the copy constructor (inside pop ) throws an exception? (see comment by @Steve Jessop)
source share