Returning a T from pop is inherently exception-unsafe, even if you return a copy of data. This is why STL doesn''t do it.
You''re passing data/returning data by value instead of by reference in push and peek. If ''t'' isn''t a built-in type, this can be very expensive.
Your QNode does a 2-step construction of its data each time: first the default ctor, then the assignment operator (manually). This can be expensive. You should have QNode constructed from a ''t'', using the copy constructor to initialize data.
Your push function is just funky. Hard to understand what''s going on, but this is where meaningful variable names and/or comments can help--''c'' and ''d'' aren''t very helpful. Looks like you''re traversing the list on each insert to put the item at the end. This is very inefficient. You should be using a first & last pointer to get constant-time insertions.
It''s strange that you get the error on the line that says ''delete c'', since c is a copy of first, and first is dereferenced before the delete. Therefore first isn''t null when you get this error, but somehow it''s not a legal pointer. Are you sure you aren''t deleting QNodes somewhere else?
Other than that, can''t see why you''re getting the error.
Here''s how to fix your code so that you''ll get no errors, be exception safe (mostly--your pop kinda screws it up) and be extremely efficient:
template
class Queue{private: std::list<t> m_list;public: void push (const t &item) { m_list.push_back (item); } t pop() { t item (m_list.front ()); m_list.pop_front (); return item; } BOOL empty() const { return m_list.empty (); } const t &peek() const { return m_list.front (); }};