Problem with sort

I don't understand why this code doesn't work.
Note that i have written the bool function in .h StudentBook class, order function in .cpp StudentBook class, i have included Exam class in StudentBook class,grade() is a function of Exam class and _v is a vector of Exam object.

bool cmd(const Exam& e1, const Exam& e2)
{
if (e1.grade() != e2.grade() ) return e1.grade()<e2.grade();
}


void StudentBook::order()
{
sort(_v.begin(),_v.end(), cmd);
}

The compiler returns this error: "no matching function for call to 'StudentBook::cmd()'

If i write sort in this way
sort(_v.begin(),_v.end(), cmd(const Exam& e1, const Exam& e2));

it returns this error:
expected primary-expression before 'const'
Last edited on
1) Please use code tags when posting code, to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/

2) Can you show us the declaration for cmd() ?
StudentBook::cmd()'
cmd() is not a member method
i will use code tags!
thank you guys but i have solved the problem using an overload operator <
i have solved the problem

good, but just so you know your cmd() function was also fine. you just had to supply it as the predicate argument to std::sort() without the StudentBook:: scope
Topic archived. No new replies allowed.