I have a list with objects Studenti which are defined with multiple parameters. I want to sort this list of Students, first by their mean and if means are the same I sort them alphabetically.
In my class Student I declared this header function:
bool mediaDescrescator(const&, const&);
Which is implemented in this way:
bool Studenti::mediaDescrescator(const Studenti& a, const Studenti& b)
{
if(a.medie_ != b.medie_)
{
return (a.medie_ > b.medie_);
}
return (a.nume_ > b.nume_);
}
medie_
is a double private member of Studenti
nume_
is a std::string private member of Studenti
In main I have a list of Studenti:
std::list<Studenti> listaStud_ = {stud1, stud2, stud3, stud4, stud5};
Function call:
std::sort(listaStud_.begin(), listaStud_.end(), mediaDescrescator);
My error is: mediaDescrescator was not declared in this scope.
I've seen other topics about this type of sort and they are declared like mine, I tried even with vector type instead of list.
mediaDescrescator
is called without (), because it must be passed as a function pointer or function object.