The name is the main question. Exact scenario (I use namespace std; '):
void SubstringMiner::sortByOccurrence(list<Substring *> & substring_list) { list::sort(substring_list.begin(), substring_list.end(), Substring::OccurrenceComparator); }
This is the definition of a comparator:
class Substring {
Comparator implementation is intuitive and trivial. I also use a very similar comparator in std :: set, and it works great. When I add the sortByOccurrence () function, it gives me an error in the name.
What should I do?
EDIT: Now I try to pass Substring :: OccurrenceComparator () as a comparator and get 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
Now my line of code:
list<Substring *>::sort(substring_list.begin(), substring_list.end(), Substring::OccurrenceComparator());
I cannot delete the template, or it gives me an error saying that the template parameters were incorrect.
source share