Is it posible to make a sort function with an pointer to an callback?
PHP Code://...
void Sort(LPCSTR *CallBackName) // This can't compile....!!
{
qsort(this->GetData(), this->GetSize(), sizeof(ARG_T), CallBackName);
//...
Printable View
Is it posible to make a sort function with an pointer to an callback?
PHP Code://...
void Sort(LPCSTR *CallBackName) // This can't compile....!!
{
qsort(this->GetData(), this->GetSize(), sizeof(ARG_T), CallBackName);
//...
The prototype for qsort is
So the function you want must have the same prototype as the compare function:Code:void qsort(
void *base,
size_t num,
size_t width,
int (__cdecl *compare )(const void *, const void *)
);
Code:int compare( const void *arg1, const void *arg2 )
{
ARG_T *argT_1 = (ARG_T *)arg1;
ARG_T *argT_2 = (ARG_T *)arg2;
if (argT_1 > argT_2 ) return 1;
else if (argT_1 < argT_2) return -1;
else return 0;
}
void Sort(int (__cdecl *CallBackName)(const void *, const void *) ) {
qsort(this->GetData(), this->GetSize(), sizeof(ARG_T), CallBackName);
}
Thanks!!!