On Sunday, 10 April 2016 18:13:05 UTC+3, elmazzun wrote:
> > data_packet first = q.front();
> > q.pop();
> >
> >
> > If you replaced
> >
> > data_packet *pkt;
> >
> > with
> >
> > data_packet& pkt;
> >
> > it would compile, but it wouldn't work, as the reference would be
> > invalided by q.pop();
> >
>
> That's what I was doing, indeed it compiled but the fields in my
> retrieved struct shows horrible numbers.
> Even commenting the pop() instruction did not make it work...
That sounds like your code has some more issues than that 'pop'.
The logic is that if copy constructor of popped element throws during
'pop' then first the implementation of 'pop' and after that you will
have quite bad situation. So no copies are made during 'pop'. Think
about it.
Therefore you should 'pop()' *after* you have done everything that you
want with the element. Including (if you need to) copying or moving
from it.
After 'pop' the element is gone and destroyed. Debug versions of some implementations also fill the memory where it was with most unlikely
garbage to ensure that it does not work and draws your attention.