Funktory, jak to sie je

0

Piszac sobie wlasna klase, tworze vector elementow tej klasy, aby moc go sortowac, musze udostepnic operator< lub operator(), czyli np:

bool operator()(const Person& p1, const Person& p2)
{
  return p1.lastname() < p2.lastname() ||
         (p1.lastname() == p2.lastname() &&  p1.firstname() < p2.firstname());
}
...
dziala:
 sort(p.begin(), p.end(), Person());


dla

bool operator<(const Person& p1, const Person& p2)
{
  return p1.lastname() < p2.lastname() ||
         (p1.lastname() == p2.lastname() &&  p1.firstname() < p2.firstname());
}

 sort(p.begin(), p.end());




dla

bool personSortCriterion (const Person& p1, const Person& p2)
{
  return p1.lastname() < p2.lastname() || 
         (p1.lastname() == p2.lastname() &&  p1.firstname() < p2.firstname());
}


dziala:
 sort(p.begin(), p.end(),     
         personSortCriterion); 
 

I tu moje pytanie, w kazdej sytuacji, dla kazdego kontenera i algorytmu mamy taie podwojne mozliwosci ?

0

zamiast podwojne - potrojne :)

z gory dziek iza info :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1