Maybe I'm going crazy here. I thought that a queue deletes its copied
elements when the queue is destructed. Can someone explain why the
following code works?
--------------------------
string *p;
{
queue<string> q;
string x = "hello";
q.push(x);
p = &q.front(); // p points to "hello" stored in the queue
cout << "p, *p: " << p << ", " << *p << endl;
q.pop(); // shouldn't this invalidate p?
cout << "p, *p: " << p << ", " << *p << endl;
}
// the queue is dead, why does this work?
cout << "p, *p: " << p << ", " << *p << endl;
-------------------------
Prints out hello everytime!
Scott