class Employee : public Person // Inheritance
{
private:
Record myRecord; // Composition
Project* myProject = nullptr; // Aggregation
int id;
public:
Employee(string name, double s, int i)
: Person(name), myRecord(s), id(i) {}
friend ostream& operator<<(ostream& out, Employee& me)
{
out << (Person &)me << endl; // (a)
out << me.myRecord << endl; // (b)
if (me.myProject != nullptr) out << *me.myProject << endl; // (c)
out << me.id << endl; // (d)
return out;
}
};
The Person, Project, and Record member variables are private, so they cannot be accessed directly from the Employee class. The Employee class must use the public interfaces (i.e., the public member functions) of the superclass and the two-part classes to access their private members. The exact formatting (e.g., spaces and new lines) is not logically significant.
out << (Person &)me matches the Person inserter function parameter list.