To fix the first error, you need to cast from void*
inside the comparison routine:
auto p1 = static_cast<const struct zipType*>(v1);
To fix the second error, I think we again need to cast, but this time to void*
:
qsort(static_cast<void*>(zip), count, sizeof(zipType*), compare)
Honestly, I'm not sure why this cast is needed. If I'm remembering my conversion rules correctly, zipType*
should be convertible to void*
implicitly. If anyone knows, post a comment and I'll edit the answer or, if you can, just edit the answer.
Note that you want the size of the the elements in the array for the third parameter, not sizeof(int)
here. You have an array of zipType*
not int
.
Since you are using C++ (deduced because you are using std::cout
), though, try std::sort
. It is more type-safe and can often be optimized better.
std::sort(zip, std::advance(zip, count), compare)
Also, since this is C++, you don't need to say struct zipType
. You can just say zipType
.