mfc >> qsort error message

by eric57e » Mon, 24 Nov 2003 20:28:01 GMT

I have tried to use qsort to sort a long array in a MFC program.
I have the followinf message
error C2664: 'qsort' : cannot convert parameter 4 from 'int (const
void *,const void *)' to 'int (__cdecl *)(const void *,const void *)

here is my code

void CQuickSortTestDlg::OnBnSort()
{
long vArray[]={9,6,7,6,3,2,1,8,0,4,5,4};
qsort((void*) vArray,(size_t) 12, sizeof(long), compare);
CString str,Msg;
for (int i=0 ; i < 12;i++)
{
str.Format("%d ",vArray[i]);
Msg+=str;
}
MessageBox(Msg);

}

int CQuickSortTestDlg::compare(const void *el1,const void *el2)
{
int res=*((long*)el1) - *((long*)el2);
return res;
}

I have read some documentation about decorated function names.
Should I use such a notation here?

It would be very nice If someone could tell me what is wrong in my
code.

Eric


mfc >> qsort error message

by Scott McPhillips [MVP] » Mon, 24 Nov 2003 21:27:18 GMT





qsort is a C compatible function and can not use a C++ member function
as the callback - C++ function signatures differ. Change your compare
function declaration to be a static class member, or not a member of a
class.

--
Scott McPhillips [VC++ MVP]




mfc >> qsort error message

by Joseph M. Newcomer » Tue, 25 Nov 2003 09:37:33 GMT

Is compare declared as a static method?
joe




Joseph M. Newcomer [MVP]
email: XXXX@XXXXX.COM
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm


Similar Threads

1. Error message from error provider when I don't select an item

Hi all!

I am creating a class to databing to a form. My difficulty is with combobox. 
I have a field that is related to the customer table, where the customer ID 
is an integer and I show its name in the combobox. In the class I have a 
property of the type int to catch the ID. Everything works fine if I select 
an item in the combobox, however if I don't select an item, the error 
provider shows the following message:

"Object of type 'System.DBNull' cannot be converted to type 'System.Int32'"

Does someone has an idea how can I do to no have this message?

sds,
Vanessa

2. Compiler error - incorrect error message "illegal type for non-type template parameter"

3. Yahoo crawler returns error message '500 internal error' for c# si

4. Terrifying error messages produced by vc .exe: win32 error 11 - Microsoft Visual C++/VC++

5. Error messages produced by vc .exe: win32 error 11

Hello and thanks for helping.

I have been developing a program on a win98 computer but then switched to a
w2k computer for a while.   Now I have to go back to the win98 computer and
support the program on other win98 computers.  Problem is, when I
reinstalled VC++, cleaned then rebuilt all, then executed, the following 2
dialog boxes appeared:

1)"Error starting program"  "Program appears to be corrupt"

2) "Microsoft Visual C++"  "Incorrect format (win32 error 11)"

this same project, when compiled for win98 3 months ago, worked fine.
This same project, when compiled for win2k on win2k yesterday worked as
well.

Some of the work I did over the last 3 months is somehow incompatible with
win98.  Can anyone help me get a clue as to how to figure out whaaa?  cmon
throw a newbie a bone.  My date is set correctly.

Thank you,

Ivan





6. Terrifying error messages produced by vc .exe: win32 error 11

7. why the error message error:illegal call of non-static member func

sayu wrote:

> hello,
>         I have written my own function to perform some operation.I call it 
> from  thread i have  created in my program.But on compilation it gives the 
> following error
> error:illegal call of non-static member function.
> why such an error comes?Does it have to do with calling the function from a 
> thread?This is what i think?.
> When i declared the function as static it worked fine....
> Can i know what was exactly going wrong and if i don't want it to be static 
> what is the other solution?
> 
> Please help

The thread function must be static because it is called by the operating 
system, which does not support nonstatic C++ member functions.  If you 
wish to use or call a nonstatic function you must pass the object 
pointer to the thread, and use that to access the nonstatic function.

-- 
Scott McPhillips [VC++ MVP]

8. Mapping error codes to error messages