I'm going to make some assumptions about your array here.
1 2
|
const unsigned MAX_PATIENTS = 10; // or some number
Patient checkIn[MAX_PATIENTS]; // are you creating your array like this?
|
If you want an array of patients, I will presume you have something like the above in place. If so, you need a default constructor that creates 'invalid' patients, so the above code works.
I'm also not sure what you're doing with the
--id bit; surely, if anything, it's
++id or
id++? I need more information.
All these problems can be solved, however, by using the eminent
std::vector:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#include <vector>
// ...
std::vector<Patient> patients; // no need to give a size or default constructor
// ...
Patient p(id, first, last, Date(m, d, y), Did);
patients.push_back(p); // put the patient at the end of the array
// or
patients.emplace_back(id, first, last, Date(m, d, y), Did); // construct inside object
patients[0].getID(); // get the ID of the first patient
// loop over entire array with one of:
for (int i = 0; i < patients.size(); ++i) { patients[i].getID(); ... }
for (auto it = patients.begin(); it != patients.end(); ++it) { it->getID(); ... }
for (auto&& p : patients) { p.getID(); ... }
|
EDIT:
Just noticed your last sentence. You defined
first as a string on line 3, but you're trying to define
first again on line 12 as a Patient.
EDIT2:
If you have an array of patients, the easiest method for you would probably be to just loop through and see if it exists:
1 2 3 4 5 6 7 8
|
// assuming you're using a C-style array
bool doesPatientExist(Patient* patients, int checkID) {
for (int i = 0; i < NUM_PATIENTS; ++i) {
if (patients[i].getID() == checkID)
return true;
}
return false;
}
|