You have an array of Person*
. You can only call public methods of Person
on elements of that array, even if they point to Patient
objects. To be able to call Patient
methods, you would first have to cast the Person*
to a Patient*
.
Person* person = new Patient;
person->setSomething("foo"); // ERROR!
Patient* patient = dynamic_cast<Patient*>(person);
if (patient)
{
patient->setSomething("foo");
} else
{
// Failed to cast. Pointee must not be a Patient
}