Accessing subclass members from a superclass pointer C++
- by Dr. Monkey
I have an array of custom class Student objects. CourseStudent and ResearchStudent both inherit from Student, and all the instances of Student are one or the other of these.
I have a function to go through the array, determine the subtype of each Student, then call subtype-specific member functions on them.
The problem is, because these functions are not overloaded, they are not found in Student, so the compiler kicks up a fuss.
If I have a pointer to Student, is there a way to get a pointer to the subtype of that Student? Would I need to make some sort of fake cast here to get around the compile-time error?