I wonder if there is support in STL for this:
Say I have an class like this :
class Person
{
public:
int getAge() const;
double getIncome() const
You don't need to create a class - just write a function:
#include
#include
using namespace std;
struct Person {
int age;
int getage() const {
return age;
}
};
bool cmp( const Person * a, const Person * b ) {
return a->getage() < b->getage() ;
}
int main() {
vector v;
sort( v.begin(), v.end(), cmp );
}