开发者

Custom Comparator for Priority Queue of a pair<int, pair<int, int> >

#include <iostream>
#include <queue>
using namespace std;

template< typename FirstType, typename SecondType >
struct PairComparator {
  bool operator()( const pair<FirstType, SecondType>& p1, const pair<FirstType, SecondType>& p2 ) const 
    {  if( p1.first < p2.first ) return true;
        if( p2.first < p1.first ) return false;
        //return p1.second < p2.second;
    }
};

priority_queue<pair<int, pair<int, int> > > q;

int main() {
    q.push(make_pair(1, make_pair(2,3)));
    pair<int, pair<int, int> > a = q.top;
    return 0;
}

This gives me the error

pqpair.cpp:18: error: conversion from ‘<unresolved overloaded function type>’ 
to non-scalar type ‘std::pair<int, std::pair<int, int> >’ requeste开发者_如何转开发d

I found the PairComparator code from the cplusplus.com forums


pair<int, pair<int, int> > a = q.top;

Should be changed to:

pair<int, pair<int, int> > a = q.top();
                                    ^
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜