I'm trying to sort a list of pointers (in my case each pointer is of type Job) I intend to sort the jobs by their serial number
void Container::jobSort(list<Job*> &jobs) { sort(jobs.begin(), jobs.end(), jobSerialCompare); } bool Container::jobSerialCompare(const Job *jobA,const Job *jobB) { return (jobA->getSn()<jobB->getSn()); }
The error I am getting is:
error: no matching function for call to 'sort(std::_List_iterator<Job*>, std::_List_iterator<Job*>, <unresolved overloaded function type>)' /usr/include/c++/4.2.1/bits/stl_algo.h:2852: note: candidates are: void std::sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = std::_List_iterator<Job*>, _Compare = bool (Container::*)(const Job*, const Job*)] make: *** [src/Container.o] Error 1
I managed to resolve this error by changing the code as follows:
struct compare { bool operator()(const Job *jobA, const Job *jobB) { return (jobA->getSn()<jobB->getSn()); } }; void Container::jobSort(list<Job*> &jobs) { jobs.sort(compare()); }
Compilation error now, but I wonder what is wrong with my initial steps, help is welcome, greetings
EDIT - Thanks so much for helping everyone! all the different answers helped draw a sharper image
Matan source share