|
-
May 4th, 2004, 06:41 AM
#1
Pointer to an CallBack
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);
//...
/* Regards, David Smulders */
-
May 4th, 2004, 06:53 AM
#2
The prototype for qsort is
Code:
void qsort(
void *base,
size_t num,
size_t width,
int (__cdecl *compare )(const void *, const void *)
);
So the function you want must have the same prototype as the compare function:
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);
}
-
May 4th, 2004, 07:54 AM
#3
/* Regards, David Smulders */
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|