June 2025
Intermediate to advanced
1093 pages
33h 24m
English
You have now learned about the special operator= method, which is called by the compiler when you write the following:
Data data{};Data newData{};data = newData;
The equal sign = of the assignment is also just a binary operator with a right operand and a left operand. It is called infix notation when the operator symbol is between the two operands. The compiler translates this into the following method call:
data.operator=(newData); // method notation
Although operator= is not a normal identifier, it is allowed in this usage form—but only if you have actually defined such a method.
However, you have also redefined another operator: the operator<< output operator. To output Year to an ostream, you have overloaded a free ...
Read now
Unlock full access