Implementing Associations

By Frank Hellwig

Dr. Dobb's Journal June 1998

void
Person::addPet(Dog* dog)
{
  int ndogs =
    getObjects("dog").entries();
  if (ndogs > 3) {
    cerr << "Too many dogs."
         << endl;
    return;
  }
  associateWith(dog,
                "dog",
                "person");
}

Example 2: The addPet() function restricting the number of pets to three.

Back to Article


Copyright © 1998, Dr. Dobb's Journal