Need of declaring a data member directly inside constructor

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
typedef priority_queue<int, vector<int>, function<bool(int,int)>> mypq_type;

class Node {
    public:
     bool end=false;
     unordered_map<char,int> next;
     mypq_type pq;
     int sp=-1;

     Node(function<bool(int,int)> comparator) {
        pq (comparator);
        //mypq_type pq ((comparator));
        //this->pq=pq;
    }
};




Error: Char 9: error: type 'mypq_type' (aka 'priority_queue<int, vector<int>, function<bool (int, int)> >') does not provide a call operator
pq (comparator);

As you see I need to pass a custom comparator function for the priority queue pq which is a data member for a class.

I also tried the commented code, It didn't work

Last edited on
to call the constructor of base class and member variables use the initializer list
1
2
3
4
5
6
7
Node(function<bool(int,int)> comparator): //colon
   //here you call the constructors
   pq(comparator)
{
   //here all your members are already constructed, and you may operate on them
   pq.push(42);
}
Topic archived. No new replies allowed.