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);
Приведенный выше код давал мне некоторую искаженную ошибку, которая также есть в некоторых других строках (помещает последние в коде), но когда я изменил функцию comp2 на следующую, все ошибки исчезли.
bool comp2(node* a,node* b){
assert(a && b && "comp2 - null argument");
if(a->value < b->value){ return true; }
return false;
}
Есть ли какое-либо объяснение этому?
ОШИБКА: /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;
}