typedef struct { int a; int b; int c; int d } A;
queue <A> q;
A* ptr;
q.push({1,2,3,4});
ptr = &(q.front());
q.pop();
ptr->a;
...
I figured out that this code might cause segmentation fault. because ptr
ends up pointing to the popped element.
but I don't know the exact reason why this happens. I just presume that pop
operation interally deallocates the memory for the popped. Is my presumption right? or any other reasons?