我無法弄清楚如何解決編譯錯誤C2664,這讓我瘋狂的整晚!調用qsort()會導致錯誤。我要排序存儲在數組中ID2IX的數組,radioIDs指出:不可理解的VC++ 6編譯錯誤C2664
typedef struct id2ix { // struct maps radio id to array index
int id; // radio id
int ix;
} ID2IX;
ID2IX *RadioIDs = NULL; // radio IDs integer
.....
RadioIDs = (ID2IX*) malloc(totRadios * sizeof(ID2IX));
if (RadioIDs == NULL) {
return FALSE;
}
.....
// the qsort compar function
int // sort the id2ix array by radioID
//sort_by_radioID (ID2IX*one , ID2IX*two) { // tried this signature
sort_by_radioID (void*one , void*two) { // tried this signature, also
return ((ID2IX*)one)->id - ((ID2IX*)two)->id;
}
// call to qsort that will not compile
qsort(RadioIDs, totRadios, sizeof(ID2IX), sort_by_radioID);
我擺脫這種錯誤是:
Objects.cpp(295) : error C2664: 'qsort' : cannot convert parameter 4
from 'int (void *,void *)'
to 'int (__cdecl *)(const void *,const void *)'
None of the functions with this name in scope match the target type
到底什麼是我做錯了什麼?
編輯:謝謝大家。我們C/ASM編碼器,我們不打擾'回合沒有該死const。
如果你添加編譯器告訴你缺少的const,會發生什麼? – Mat 2012-02-22 10:38:09
嘗試使用簽名'int sort_by_radioID(const void * one,const void * two)'。 – Naveen 2012-02-22 10:38:22
檢查你的默認調用conv以及,如果它不是'__cdecl',你需要明確地使用'__cdecl'作爲函數 – Necrolis 2012-02-22 10:41:32