C++ priority_queue with lambda comparator error

前端 未结 4 1035
时光说笑
时光说笑 2020-11-30 21:59

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 g

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-30 22:28

    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, decltype( comp ) >
         adjlist_pq( comp );
    

提交回复
热议问题