#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;
}
这给了我错误
pqpair.cpp:18: error: conversion from ‘<unresolved overloaded function type>’
to non-scalar type ‘std::pair<int, std::pair<int, int> >’ requested
我在cplusplus.com论坛找到了PairComparator
代码
答案 0 :(得分:3)
pair<int, pair<int, int> > a = q.top;
应改为:
pair<int, pair<int, int> > a = q.top();
^