首页 > 解决方案 > 从 std::priority_que 复制到 typdef 边缘

问题描述

我有typedef std::pair<int , std::pair<std::string, std::string>> edge;

我把我的边缘放入std::priority_que<edge, std::vector<edge>, Compare> que;

当我现在尝试que.pop()回到边缘变量时,会出现错误。这是为什么?

que = priority_que with edges
edge e = que.pop() // this does not work

标签: c++queue

解决方案


因为std::priority_queue::pop()不返回任何东西。

您需要先调用top()以提取元素。

edge e = que.top();
que.pop();

推荐阅读