2011-07-08 23 views
2
#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; 
} 

これは私にエラーを与えるカスタムコンパレータ<int型、ペア<int, int>>

pqpair.cpp:18: error: conversion from ‘<unresolved overloaded function type>’ 
to non-scalar type ‘std::pair<int, std::pair<int, int> >’ requested 

私はcplusplus.comフォーラム

+1

プログラムでは、 'PairComparator'を比較器としてpriority_queueに渡していません。 'std :: less >'が何をするのでしょうか?私たちはそれを使う必要がありますか?感謝! – rajatkhanduja

答えて

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

からPairComparatorコードを見つけました変更する必要があります。

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

ありがとう!そのような単純な間違いであったことを認識していない> – Billy

関連する問題