In the above examples we provided our own LessThan-function, so we were using this qsort definition:
template <typename RandomAccessIterator, typename LessThan>
inline void qSort(RandomAccessIterator start, RandomAccessIterator end, LessThan lessThan)
template <typename RandomAccessIterator, typename LessThan>
inline void qSort(RandomAccessIterator start, RandomAccessIterator end, LessThan lessThan)
To copy to clipboard, switch view to plain text mode
The third argument is a function pointer to a user-defined-function with two parameters of the container type, that returns true only if the first argument is "less" than the second.
bool compareNames(const T &t1, const T &t2) const ..
bool compareNames(const T &t1, const T &t2) const ..
To copy to clipboard, switch view to plain text mode
So you do not give any parameters to compareNames. You just call:
qSort(strlist.begin(),strlist.end(),compareNames);
qSort(strlist.begin(),strlist.end(),compareNames);
To copy to clipboard, switch view to plain text mode
qSort then calls compareNames each time it needs to establish the order of two strings while sorting the whole thing.
HIH
Johannes
Bookmarks