I am creating a hospital management system program. |
... that real lives of real people will depend on? I hope not. I hope it is just a homework.
A Doctor dies. She must inform all her Patients. The Patients must remove that Doctor from their lists. The Patients may request new Doctor from the hospital. Again an update to Patients' lists and other Doctors' lists. Complex, but doable.
Think of an alternative:
* Doctor has no list (Does not depend on Patient)
* Patient has no list (Does not depend on Doctor)
* Hospital has a list of Patient-Doctor pairs
* Hospital manages that list
1 2 3 4 5
|
class Doctor{
private:
Patient *patient; // Is this "a list"?
//...
};
|
That pointer can either point to one Patient or to an array of Patients.
One Patient is ok (as long as you manage pointer invalidation), but not "a list".
If it points to an array, then how many elements does that array have?
An element of an array is a Patient object. That sounds like a copy. You should not clone people; troublesome.