The const reference returned by priority_queue
's top()
changes after calling pop()
(visual studio 2015)
priority_queue<int> queue;
queue.push(1);
queue.push(2);
queue.push(3);
const int & m = queue.top();
cout << m << endl; // 3
queue.pop();
cout << m << endl; // 2
queue.pop();
cout << m << endl; // 1
If get top value by auto & m = queue.top();
, then output is also 3 2 1
.
While if get top value by auto m = queue.top();
, then output is 3 3 3
.
What's mechanism behind this ?