#include <stdio.h>

struct Person {
    const char *name;
    int age;
};

class PersonList {
    struct Node {                       /* hidden list structure */
        Person data;
        Node *next;
    };
    Node *first;
public:
    class Iter {                        /* behaves like Person * */
        Node *n;
    public:
        Iter(Node *p) : n(p) {}
        Person *operator->() const { return &n->data; }
        Iter &operator++() { n = n->next; return *this; }
        bool AtEnd() const { return n == 0; }
    };
    PersonList() : first(0) {}
    ~PersonList();
    void Add(const char *name, int age);
    Iter Begin() const { return Iter(first); }
private:
    PersonList(const PersonList &);
    void operator=(const PersonList &);
};

PersonList::~PersonList()
{
    while (first) {
        Node *t = first;
        first = first->next;
        delete t;
    }
}

void PersonList::Add(const char *name, int age)
{
    Node *t = new Node;

    t->data.name = name;
    t->data.age = age;
    t->next = first;
    first = t;
}

int main()
{
    PersonList list;

    list.Add("Ada", 36);
    list.Add("Ken", 81);
    list.Add("Dennis", 70);
    for (PersonList::Iter it = list.Begin(); !it.AtEnd(); ++it)
        printf("%-7s %d\n", it->name, it->age);    /* like a pointer */
    return 0;
}
