#include <string>
#include <vector>
#include <algorithm>
#include <iostream>

class Foo
{
private:
    std::string name;
    int age;

public:
    Foo(const char *_name, int _age)
        : name(_name)
        , age(_age)
    {}

    const char *getName(void) const { return name.c_str(); }
    int getAge(void) const { return age; }
    
};

bool compareAge(Foo *foo1, Foo *foo2)
{
    return foo1->getAge() < foo2->getAge();
}

namespace my
{
    typedef std::vector<Foo *> vector;
}

using my::vector;
using std::sort;
using std::cout;
using std::endl;

int main(void)
{
    Foo foo1("A", 10);
    Foo foo2("B", 30);
    Foo foo3("C", 5);
    vector foo_v;

    foo_v.insert(foo_v.end(), &foo1);
    foo_v.insert(foo_v.end(), &foo2);
    foo_v.insert(foo_v.end(), &foo3);

    sort(foo_v.begin(), foo_v.end(), compareAge);

    // Print out the contents of foo_v.
    for(vector::iterator it(foo_v.begin()); it != foo_v.end(); ++it)
    {
        Foo *&pFoo = *it;
        cout << pFoo->getName() << endl;
    }
}
