struct st{
struct node{
int x;
}a[1000];
int cmp(st::node c, st::node d)
{
return c.x < d.x;
}
void init(int n )
{
sort(a+1,a+1+n,st::cmp);
}
};
这样会报错,该如何解决
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
报什么错误,cmp的参数好像是引用传值的。
问题:标准库中的sort的原型如下
void sort ( RandomAccessIterator first, RandomAccessIterator last,Compare comp );
要求first和last迭代器都要有加1的功能,而你的代码中的node*没有相关的+1操作。
如下代码可以证明问题
编译错误
21 13 E:\DEV CPP\HELLO.cpp [Error] lvalue required as increment operand