我正在尝试使用stl中的next_permutation进行排列,但是我遇到了错误,我无法弄清楚如何修复它。我已经尝试了谷歌搜索,但是出现的唯一结果是人们使用相同的函数和函数的变量名称,但事实并非如此。
这是错误:
'__comp' cannot be used as a function
以下是代码:
struct rectangle{
int n;
int h;
int w;
};
bool check(const rectangle& rect1,const rectangle& rect2){
return rect1.n < rect2.n;
}
do{
//...
} while ( next_permutation(recs.begin(), recs.end(), check) ); // Getting error on this line.
以下是完整的源代码以及示例输入,以防需要http://pastebin.com/eNRNCuTf
答案 0 :(得分:14)
H = rec4.w + max(rec1.h, rec2.h, rec3.h);
您不希望在那里传递rec3.h
- 错误消息只是说max
的第3个参数不能用作函数。我相信你的意图:
H = rec4.w + max(max(rec1.h, rec2.h), rec3.h);