typedefbool compF(int, int);
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)){}
};
class Trie {
public:
vector<Node*> tr;
vector<int>& times;
vector<string>& sentences;
Trie(vector<string>& sentences, vector<int>& times): times(times), sentences(sentences){
tr.push_back(new Node(&comparator));
}
bool comparator(int a, int b) {
if (times[a] != times[b]) {
return a > b;
}
return sentences[a].compare(sentences[b]) < 0 : true: false;
}
void insert(string& s,int i) {
int p=0;
vector<char> nS;
for(char ch: s) {
if (tr[p]->next.find(ch) == tr[p]->next.end()) {
tr[p]->next[ch]=tr.size();
tr.emplace_back(new Node(&comparator));
}
}
In places like tr.push_back(new Node(&comparator));tr.emplace_back(new Node(&comparator));
Error: must explicitly qualify name of member function when taking its address
Initially tried passing just "comparator" function without &
Got this
reference to non-static member function must be called
tr.push_back(new Node(comparator));
minimum (but far from best) fix is probably to bind your member comparator to this using std::bind: tr.push_back(new Node(bind(&Trie::comparator, this, _1, _2)));
live demo https://wandbox.org/permlink/0VMz7sfeagi3Bn9S
(I tried to keep the rest intact, but "sentences[a].compare(sentences[b]) < 0 : true: false" didn't compile so it was replaced with sentences[a] < sentences[b])