Yes, this is just an example. I'm trying to dust off my C++ skills after years and years of programming in other languages. |
Unfortunately, you've picked a really nasty problem to play around with pointers. If you just want to mess around with the language, try implementing your own linked list or binary tree.
The problem with genealogical relationships is that they gets incredibly complex. Here are some problems with your code:
- when you set person1.addSpouse(person2), it should make each person a spouse of the other, not just one. Don't rely on the caller to keep this relationship.
- If you delete a person, you remove their children, but you don't remove the person from the parent's list of children.
- A child, by definition, has two parents. So when you add a child to one person, shouldn't you add them as a child to their other parent?
To handle all of this in a generic way, it would be better to assign each person an ID. A collection of Persons holds the people. Each person object has a collection of relationships:
1 2 3 4
|
class Relationship {
RelationshipType type; // type of relationship
unsigned id; // id of the other party.
};
|
Now if you want to delete a person, then you remove them from the collection of people. Part of that process is to go through all the other people and remove any relationships to the one being deleted.
Like I said, practice with a linked list or binary tree. :)