22.3.3. Resolving Multiple Inheritance Conflicts

[ fromfile: multiple-inheritance.xml id: multinheritanceconflicts ]

Figure 22.4. Person - Student - Teacher

Person - Student - Teacher

class GradTeachingFellow : public Student,
                           public Teacher {
     // class member functions and data members
};
[Important]Question

What happens when you call getDepartment() on a GraduateTeachingFellow?

   GraduateTeachingFellow gtf;
   Person* pptr = &gtf;
   Student * sptr = &gtf;;
   Teacher* tptr = &gtf;
   gtf.Teacher::getDepartment();
   gtf.Student::getDepartment();
   sptr->getDepartment()
   tptr->getDepartment()
   pptr->getDepartment();   // Ambiguous: runtime error if virtual
   gtf.getDepartment();  // Compiler error: ambiguous function call