【发布时间】:2023-12-29 19:30:01
【问题描述】:
我正在使用这个结构
struct box
{
int h,w,d;
};
int compare (const void *a, const void * b)
{
return ((*(box *)b).d * (*(box *)b).w) – ((*(box *)a).d * (*(box *)a).w); // error is showing in this line
}
box rot[3*n];
qsort (rot, n, sizeof(rot[0]), compare);
我正在尝试 qsort 但显示错误表达式不能用作函数中
【问题讨论】:
-
长线中间的那个字符
–不是减号,而是一个破折号。一旦修复,您的代码compiles for me -
如果您编写了可读的代码,您可能会更容易找出错误。将所有内容浓缩为一个陈述对您没有任何好处。
-
@Igor Tandetnik 谢谢它也对我有用,但你是如何检测到的?
-
how you detect that?编译器told me. -
只需使用
std::sort。它快了很多。