#include <stdio.h>
#include <stdlib.h>

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

class PersonPtr {                       /* a pointer that checks itself */
    Person *p;
    const char *where;                  /* for the error message */
public:
    PersonPtr(Person *a, const char *w) : p(a), where(w) {}
    Person *operator->() const
    {
        if (!p) {
            fprintf(stderr, "%s: null Person pointer used\n", where);
            abort();
        }
        return p;
    }
};

static Person *find(Person *all, int n, const char *name)
{
    for (int i = 0; i < n; i++)
        if (all[i].name[0] == name[0])
            return &all[i];
    return 0;
}

int main()
{
    Person all[] = { { "Ada", 36 }, { "Ken", 81 } };
    PersonPtr a(find(all, 2, "Ken"), "lookup Ken");
    PersonPtr b(find(all, 2, "Bob"), "lookup Bob");

    printf("%s is %d\n", a->name, a->age);
    printf("%s is %d\n", b->name, b->age);      /* stops here, clearly */
    return 0;
}
