<i id='xoNr1'><tr id='xoNr1'><dt id='xoNr1'><q id='xoNr1'><span id='xoNr1'><b id='xoNr1'><form id='xoNr1'><ins id='xoNr1'></ins><ul id='xoNr1'></ul><sub id='xoNr1'></sub></form><legend id='xoNr1'></legend><bdo id='xoNr1'><pre id='xoNr1'><center id='xoNr1'></center></pre></bdo></b><th id='xoNr1'></th></span></q></dt></tr></i><div id='xoNr1'><tfoot id='xoNr1'></tfoot><dl id='xoNr1'><fieldset id='xoNr1'></fieldset></dl></div>
    • <bdo id='xoNr1'></bdo><ul id='xoNr1'></ul>

        <tfoot id='xoNr1'></tfoot>
      1. <legend id='xoNr1'><style id='xoNr1'><dir id='xoNr1'><q id='xoNr1'></q></dir></style></legend>

        <small id='xoNr1'></small><noframes id='xoNr1'>

        带有 lambda 比较器错误的 C++ priority_queue

        C++ priority_queue with lambda comparator error(带有 lambda 比较器错误的 C++ priority_queue)
        • <bdo id='34bee'></bdo><ul id='34bee'></ul>
              <tbody id='34bee'></tbody>
            <i id='34bee'><tr id='34bee'><dt id='34bee'><q id='34bee'><span id='34bee'><b id='34bee'><form id='34bee'><ins id='34bee'></ins><ul id='34bee'></ul><sub id='34bee'></sub></form><legend id='34bee'></legend><bdo id='34bee'><pre id='34bee'><center id='34bee'></center></pre></bdo></b><th id='34bee'></th></span></q></dt></tr></i><div id='34bee'><tfoot id='34bee'></tfoot><dl id='34bee'><fieldset id='34bee'></fieldset></dl></div>

              <legend id='34bee'><style id='34bee'><dir id='34bee'><q id='34bee'></q></dir></style></legend>

                  <tfoot id='34bee'></tfoot>

                  <small id='34bee'></small><noframes id='34bee'>

                  本文介绍了带有 lambda 比较器错误的 C++ priority_queue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我尝试在 VC2010 中编译以下错误代码,但出现错误 C2974 这只发生在我包含 lambda 表达式时,所以我猜它与此有关.

                  typedef pair, int>adjlist_edge;优先队列,[](adjlist_edge a, adjlist_edge b) ->布尔{if(a.second > b.second){ 返回真;} else { 返回假;}}>adjlist_pq;

                  我知道模板定义的形式是正确的

                  priority_queue、greater>pq;

                  按预期工作.任何想法我做错了什么?lambda 是否有明显的错误,看起来我可能忽略了?感谢阅读!

                  解决方案

                  首先定义 lambda 对象,然后使用 decltype 将其传递给模板的类型,并直接将其传递给构造函数.

                  >

                  auto comp = []( adjist a, adjlist b ) { return a.second >b.第二;};优先队列,decltype(comp)>adjlist_pq(comp);

                  I have the following erroneous code which I am trying to compile in VC2010, but I'm getting the error C2974 this only occurs when I include the lambda expression, so I'm guessing it has something to do with that.

                  typedef pair<pair<int, int>, int> adjlist_edge;
                  priority_queue< adjlist_edge , vector<adjlist_edge>,
                      [](adjlist_edge a, adjlist_edge b) -> bool {
                          if(a.second > b.second){ return true; } else { return false; }
                      }> adjlist_pq;
                  

                  I know the form of the template definition is correct as

                  priority_queue<int , vector<int>, greater<int>> pq;
                  

                  Works as expected. Any ideas what I'm doing wrong? Is there something obviously wrong with the lambda that looks wrong that I might be overlooking? Thanks for reading!

                  解决方案

                  First define the lambda object, then pass it to the template's type using decltype and also pass it directly to the constructor.

                  auto comp = []( adjist a, adjlist b ) { return a.second > b.second; };
                  priority_queue< adjlist_edge , vector<adjlist_edge>, decltype( comp ) >
                       adjlist_pq( comp );
                  

                  这篇关于带有 lambda 比较器错误的 C++ priority_queue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to print vector#39;s data(如何打印矢量的数据)
                  Visual C++ appends 0xCC (int3) bytes at the end of functions(Visual C++ 在函数末尾附加 0xCC (int3) 字节)
                  How to use a variable inside a _T wrapper?(如何在 _T 包装器中使用变量?)
                  MSVC++ warning flags(MSVC++ 警告标志)
                  How to read file which contains uxxxx in vc++(如何在vc++中读取包含uxxxx的文件)
                  stack overflow error in C++ program(C++程序中的堆栈溢出错误)
                      <tbody id='wYjhI'></tbody>
                    • <bdo id='wYjhI'></bdo><ul id='wYjhI'></ul>
                      <i id='wYjhI'><tr id='wYjhI'><dt id='wYjhI'><q id='wYjhI'><span id='wYjhI'><b id='wYjhI'><form id='wYjhI'><ins id='wYjhI'></ins><ul id='wYjhI'></ul><sub id='wYjhI'></sub></form><legend id='wYjhI'></legend><bdo id='wYjhI'><pre id='wYjhI'><center id='wYjhI'></center></pre></bdo></b><th id='wYjhI'></th></span></q></dt></tr></i><div id='wYjhI'><tfoot id='wYjhI'></tfoot><dl id='wYjhI'><fieldset id='wYjhI'></fieldset></dl></div>

                    • <tfoot id='wYjhI'></tfoot>

                        <small id='wYjhI'></small><noframes id='wYjhI'>

                          <legend id='wYjhI'><style id='wYjhI'><dir id='wYjhI'><q id='wYjhI'></q></dir></style></legend>