Billy
Billy

Reputation: 23

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> >’ requested

I found the PairComparator code from the cplusplus.com forums

Upvotes: 2

Views: 6914

Answers (1)

Marlon
Marlon

Reputation: 20314

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

Should be changed to:

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

Upvotes: 4

Related Questions