class node{
public:
unsigned long long int value;
int index;
};
bool comp2(node& a,node& b){
if(a.value < b.value) { return true; }
return false;
}
vector <node*>llist,rlist;
sort(llist.begin(),llist.end(),comp2);
Run Code Online (Sandbox Code Playgroud)
上面的代码给了我一些在某些其他行(后面的代码中)的错误,但是当我改变comp2函数跟随所有错误消失时.
bool comp2(node* a,node* b){
assert(a && b && "comp2 - null argument");
if(a->value < b->value){ return true; }
return false;
}
Run Code Online (Sandbox Code Playgroud)
这有什么理由吗?
错误:/usr/include/c++/4.4/bits/stl_algo.h|124|error: invalid initialization of reference of type ‘node&’ from expression of type ‘node* const’|
如果这个(波纹管)工作,那么上面也应该工作
using namespace std;
void rep(int& a,int& b){
int c;
c=a;
a=b;
b=c;
}
int main(void){
int a=3,b=4;
rep(a,b);
cout<<a<<" "<<b;
return 0;
}
Run Code Online (Sandbox Code Playgroud)