I am trying to use nested classes instead of multiple inheritance. I am following the recommendations from the book but I keep getting an error in the constructor. Basically, Person is the grandfather, Student and Employee are the Parent and Teaching Assistant is the child. TeachingAssistant will have a nested class that will have reference to its outer class, but when I use the code from the book I get two errors
I get the error
Error 1 *"No matching constructor for Initialization of TeachingAssistant::EmployeePart"
and this error
Error 2 "Out of line definition of 'EmployeePart' does not match any declaration in 'TeachingAssistant::EmployeePart'"
Here is the code:
class TeachingAssistant : public Student
{
public:
TeachingAssistant();
private:
class EmployeePart;
EmployeePart* employee_ptr;
};
class TeachingAssistant::EmployeePart : public Employee
{
public:
EmployeePart(TeachingAssistant&);
private:
TeachingAssistant* ta_part; // Allows access back to outer class
};
Error 1 is here in this constructor
TeachingAssistant::TeachingAssistant()
{
employee_ptr = new EmployeePart(this); // Pass pointer to implicit parameter
}
Error 2 is here
TeachingAssistant::EmployeePart::EmployeePart(TeachingAssistant* taval)
: ta_part(taval) {}
Why do these errors pop up if I am providing the constructors?