Hi,
(pardon the noob question in advance)
I have 4 classes:
class Person {};
class Student : public Person {};
class Employee : public Person {};
class StudentEmployee : public Student, public Employee {};
Essentially Person
is the base class, which are directly subclassed by both Student
and Employee
. StudentEmployee
employs multiple inheritance to subclass both Student
and Employee
.
Person pat = Person("Pat");
Student sam = Student("Sam");
Employee em = Employee("Emily");
StudentEmployee sen = StudentEmployee("Sienna");
Person ppl[3] = {pat, sam, em};
//compile time error: ambiguous base class
//Person ppl[4] = {pat, sam, em, sen};
When I use an array of Person
, the base class, I can put Person
and all of its subclasses inside this array. Except for StudentEmployee
, given the reason ambiguous base class.
Given that StudentEmployee
is guaranteed to have all the methods and attributes of Person
, is StudentEmployee
considered a subclass of Person?
- If so, Why does the compiler not allow me to assign an object to a variable of the type of its superclass?
- If not, why not; and what would be the proper way to accomplish this?
Cheers
EDIT: Preemptively, this question is NOT the same as either of the following:
http://stackoverflow.com/questions/2423231/polymorphism-relates-inheritance
http://stackoverflow.com/questions/1889996/inheritance-mucking-up-polymorphism-in-c