Hi all! The title is the main question. The exact scenario (I am 'using namespace std;'):
void SubstringMiner::sortByOccurrence(list<Substring *> & substring_list) {
list::sort(substring_list.begin(), substring_list.end(), Substring::OccurrenceComparator);
}
This is the comparator definition:
class Substring {
// ...
class OccurrenceComparator {
public:
bool operator() (Substring * a, Substring *b);
}
};
Implementation of the comparator is intuitive and trivial. I am also using a very similar comparator in a std::set and it works fine. When I add the sortByOccurrence() funcion it gives me the error in the title.
What should I do?
EDIT: I'm now trying to pass Substring::OccurrenceComparator() as the comparator, and am getting the following error:
g++ -Wall -g -c substring_miner.cpp -o obj/subtring_miner.o
substring_miner.cpp: In function ‘void SubstringMiner::sortByOccurrence(std::list<Substring*, std::allocator<Substring*> >&)’:
substring_miner.cpp:113: error: no matching function for call to ‘std::list<Substring*, std::allocator<Substring*> >::sort(std::_List_iterator<Substring*>, std::_List_iterator<Substring*>, Substring::OccurrenceComparator)’
/usr/include/c++/4.3/bits/list.tcc:303: note: candidates are: void std::list<_Tp, _Alloc>::sort() [with _Tp = Substring*, _Alloc = std::allocator<Substring*>]
make: *** [substring_miner] Error 1
My code line is now:
list<Substring *>::sort(substring_list.begin(), substring_list.end(), Substring::OccurrenceComparator());
I can't remove the template or it gives me an error saying that template parameters were wrong.