OperatorOverloading with a state variable

1
2
3
4
5
6
7
8
9
10
11
12
13
typedef pair<int,int> mp;

class Comparator {
    public: 
     vector<vector<int>> mat;
     Comparator(vector<vector<int>>& arr) : mat(arr) {};

     bool operator()(mp& p1, mp& p2) {
        return mat[p1.first][p1.second] > mat[p2.first][p2.second];
     }
};

priority_queue <mp, vector<mp>, Comparator(matrix)> pq;


The above code gives error Char 41: fatal error: template argument for template type parameter must be a type
priority_queue <mp, vector<mp>, Comparator(matrix)> pq

Hence I'm here. I intend to use make of an extra variable inside the operator everytime.
Last edited on
Looking at http://www.cplusplus.com/reference/queue/priority_queue/priority_queue/
priority_queue<mp, vector<mp>, Comparator> pq( Comparator(matrix) );
typedef priority_queue <mp, vector<mp>, Comparator> mypq_type;
mypq_type pq ((Comparator(matrix)));

this worked for me. compiler asking for extra parenthesis in `(Comparator(matrix))` ;
https://stackoverflow.com/questions/5363748/constructor-not-returning-usable-object
Topic archived. No new replies allowed.