简体   繁体   English

在向量C ++ 11中访问引用包装器元素

[英]Accessing reference wrapper elements in vector c++11

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 现在,我尝试通过执行以下操作来访问优先级队列中的第一个元素( PECMP someQueue ):

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 谢谢

Problem solved : 解决的问题

There is a get method in the std::reference_wrapper class which allows one to obtain the element store in there std::reference_wrapper类中有一个get方法,该方法允许在其中获取元素存储

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM