2 回答
The signature of std::sort()
is:
template <class RandomAccessIterator, class StrictWeakOrdering>
void sort(RandomAccessIterator first, RandomAccessIterator last,
StrictWeakOrdering comp);
So it requires two iterators and a comparator, not a pointer and a length. To fix your code, call
std::sort(pcount, pcount+structs_len, cmp_port_count);
assuming that cmp_port_count
is your comparator function which takes two port_count_t
objects by reference and returns true
when the first argument is to be ordered before the second argument, false
otherwise.
Try calling:
std::sort(pcount,pcount + 10);
std::sort takes as arguments a begin and an end iterator. So in order to sort an array you pass a pointer to the beginning of the array and a pointer to one element after the end of the array(which is always array_pointer + array_size).