elmazzun
2016-04-10 14:23:49 UTC
Hi everybody, there is something that I don't understand
about popping from std::queue.
I pushed successfully a custom struct of mine in a queue,
like this:
data_packet pkt; // typedef'd struct of mine
q.push(pkt); // push() goes fine
What I don't get is how to store the result of a popped
element from my queue, since it is "void pop()".
I read about queue::front, which returns a reference to
"the oldest element in the queue and the same element that
is popped out from the queue when queue::pop is called."
Well, if front() returns a reference&, I made like this:
data_packet *pkt;
if (!q.empty()) {
pkt = q.front();
q.pop();
}
but the compiler says:
error: cannot convert 'data_pkt' to 'data_packet* {aka data_pkt*}' in assignment.
I think it returns this error because I pushed in my queue
a data_packet struct, not a pointer to it.
But, how can I retrieve a struct from my queue and
store it, not just pop() it and lose it?
about popping from std::queue.
I pushed successfully a custom struct of mine in a queue,
like this:
data_packet pkt; // typedef'd struct of mine
q.push(pkt); // push() goes fine
What I don't get is how to store the result of a popped
element from my queue, since it is "void pop()".
I read about queue::front, which returns a reference to
"the oldest element in the queue and the same element that
is popped out from the queue when queue::pop is called."
Well, if front() returns a reference&, I made like this:
data_packet *pkt;
if (!q.empty()) {
pkt = q.front();
q.pop();
}
but the compiler says:
error: cannot convert 'data_pkt' to 'data_packet* {aka data_pkt*}' in assignment.
I think it returns this error because I pushed in my queue
a data_packet struct, not a pointer to it.
But, how can I retrieve a struct from my queue and
store it, not just pop() it and lose it?