Accessing reference wrapper elements in vector c++11

淺唱寂寞╮ 提交于 2019-12-11 11:28:36

问题


In Graph class:

typedef std::pair<double, Node&> PIRV;

In another class that uses graph:

typedef std::priority_queue<Graph::PIRV&, vector<std::reference_wrapper<Graph::PIRV>>, compareEdge> PECMP;

Now I am trying to access the first element in the priority queue (PECMP someQueue) by doing

double a = someQueue.top().first

However I get the following error:

error: ‘const value_type’ has no member named ‘first’

What is the better way to access elements stored in reference wrapper? Thanks


回答1:


Problem solved:

There is a get method in the std::reference_wrapper class which allows one to obtain the element store in there



来源:https://stackoverflow.com/questions/19910964/accessing-reference-wrapper-elements-in-vector-c11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!