访问向量c ++ 11中的引用wrapper元素 [英] Accessing reference wrapper elements in vector c++11

查看:174
本文介绍了访问向量c ++ 11中的引用wrapper元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Graph类中:

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

在另一个使用图形的类中:

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

现在我正试图访问优先级队列中的第一个元素( PECMP a $ a $ a $ a $ a $ a






$ b / code>

但我得到以下错误:

 code>错误:'const value_type'没有名为'first'的成员

更好的方式来访问存储在引用包装器中的元素?感谢

解决方案

问题解决



在reference_wrapper类中有一个 get 方法,它允许获取元素存储在其中


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

解决方案

Problem solved:

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

这篇关于访问向量c ++ 11中的引用wrapper元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆