c++中使用qsort出现的错误

来源:百度知道 编辑:UC知道 时间:2024/06/22 05:01:17
程序中我使用了这个函数
qsort(Idistance,NUM,sizeof(Idistance[1]),cmp);//对点间距离按降序排列
里面的参数都是正确的。
出现下面的错误,哪位高手指点一下啊!
error C2664: 'qsort' : cannot convert parameter 4 from 'int (const void *,const void *)' to 'int (__cdecl *)(const void *,const void *)'None of the functions with this name in scope match the target type
cmp函数我已经定义了
在C程序中这个函数是正确使用的,但在C++中,使用类的话就出现上面的问题

cmp函数必须是单独定义的(不能是类的成员函数) , 并且要声明 __cdecl

比方说 int __cdecl cmp(const void* first, const void* second)

需要自己定义cmp函数。

这个问题我也碰到过,但是还不知道原因。
将时刻关注这个问题,呵呵

贴出你的代码?