C++ priority_queue with lambda comparator error

前端 未结 4 1033
时光说笑
时光说笑 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条回答
  •  Happy的楠姐
    2020-11-30 22:31

    Following is an example for building a minheap using priority queue. I have used a lambda to define the comparator, given linked lists defined by vector &lists

    // This comparator will be used to build minheap.
    auto comp = [&](ListNode *a, ListNode *b) {
        return a->val > b->val;
    };
    
    // This priority queue is the min heap
    priority_queue, decltype(comp)> pq(comp);
    

提交回复
热议问题