ami
01-14-2007, 04:02 PM
Hello,
I have a struct and a function compare :-
struct Student_info
{
std::string name;
};
bool compare(const Student_info& x, const Student_info& y)
{
return x.name < y.name;
}
When I call the function with a vector all works ok :-
vector<Student_info> students;
Student_info record;
sort(students.begin(), students.end(), compare);
My book I should call compare like this for lists :-
list<Student_info> students;
Student_info record;
students.sort(compare);
However, I'm getting compilation error :-
error C2664: 'void __thiscall std::list<struct Student_info,class std::allocator<struct Student_info> >::sort(struct std::greater<struct Student_info>)' : cannot convert parameter 1 from 'bool (const struct Studen
t_info &,const struct Student_info &)' to 'struct std::greater<struct Student_info>'
No constructor could take the source type, or constructor overload resolution was ambiguous
Can someone please help ?
Many thanks.
I have a struct and a function compare :-
struct Student_info
{
std::string name;
};
bool compare(const Student_info& x, const Student_info& y)
{
return x.name < y.name;
}
When I call the function with a vector all works ok :-
vector<Student_info> students;
Student_info record;
sort(students.begin(), students.end(), compare);
My book I should call compare like this for lists :-
list<Student_info> students;
Student_info record;
students.sort(compare);
However, I'm getting compilation error :-
error C2664: 'void __thiscall std::list<struct Student_info,class std::allocator<struct Student_info> >::sort(struct std::greater<struct Student_info>)' : cannot convert parameter 1 from 'bool (const struct Studen
t_info &,const struct Student_info &)' to 'struct std::greater<struct Student_info>'
No constructor could take the source type, or constructor overload resolution was ambiguous
Can someone please help ?
Many thanks.