#include // std::cout #include // std::sort #include // std::vector class Person { int age ; public: Person() { age = 0 ; }; Person(int ageP ) { age = ageP ; }; int getAge() const { return age ; } }; bool myfunctionPerson (const Person& i1, const Person& j1 ) { return ( i1.getAge() < j1.getAge() ) ; } bool myfunction (int i,int j) { return (i myvector ; Person p1( 25 ) ; Person p2( 28 ) ; Person p3( 35 ) ; myvector.push_back( p2 ) ; myvector.push_back( p1 ) ; myvector.push_back( p3 ) ; // using function as comp std::sort (myvector.begin(), myvector.end(), myfunctionPerson); std::cout << "myvector contains:"; for (std::vector::iterator it=myvector.begin(); it!=myvector.end(); ++it) std::cout << ' ' << (*it).getAge() ; std::cout << '\n'; return 0; }