remove unique_ptr from queue

前端 未结 1 709
礼貌的吻别
礼貌的吻别 2020-12-09 01:07

I\'m trying to figure out how/if I can use unique_ptr in a queue.

// create queue
std::queue> q;

         


        
1条回答
  •  無奈伤痛
    2020-12-09 01:42

    You should say explicitly that you want to move the pointer out of the queue. Like this:

    std::unique_ptr p2 = std::move(q.front());
    q.pop();
    

    0 讨论(0)
提交回复
热议问题