Accessing reference wrapper elements in vector c++

2019-08-04 07:19发布

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条回答
等我变得足够好
2楼-- · 2019-08-04 07:35

Problem solved:

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

查看更多
登录 后发表回答