There are two problems which combined make your compilation to fail.
(1) This declaration and definition:
ostream& operator<< (ostream& out, Employee& e){
out << "Salary: " << e.getSalary() << " Rank: " << e.getRank() << endl;
return out;
}
Despite you don't change e
, you take it reference to non-const
. This forbids you calling this operator on an rvalue.
(2) This line
cout << (Employee)m << endl;
As said by others you are slicing m
. In addition, the cast (Employee) m
returns a temporary Employee
which is an rvalue.
In summary, the cast (Employee)m
yields an rvalue which cannot bind to e
.
You can fix either one or the other to make your code compiler but it's better to fix both problems to make your code more robust:
// ...
ostream& operator<< (ostream& out, const Employee& e) {
// ...
// ...
cout << static_cast<Employee&>(m) << endl;
// ...