使用带有结构数组的qsort

时间:2014-02-13 12:01:38

标签: c++ arrays struct qsort

当我尝试使用qsort对结构数组进行排序时,我收到此错误:qsort无法从int转换为__compar_fn_t。

源代码是:

struct idpar_exchange
{
int idp;
long long int exchange_d;

};

int ptg_partitioning::compare_by_data(const void* a, const void* b)
{
struct idpar_exchange *ia= (struct idpar_exchange *)a;
struct idpar_exchange *ib= (struct idpar_exchange *)b;
return ia->exchange_d - ib->exchange_d;
}


struct idpar_exchange v[list_part.size()][list_part.size()];

qsort(v[i],(sizeof(v[i])/(sizeof(struct idpar_exchange))),sizeof(struct idpar_exchange),compare_by_data);

0 个答案:

没有答案