A constructor with one argument provides a conversion function. For example, the following constructor enables automatic conversion of integer data into Fraction-class format: |
Fraction(int n) {set(n, 1);};
Fraction f1 = 1 + Fraction(1, 2);
but my compiler reports an error: No operator "+" matches these operands
. On the other hand, this line of code works just fine: Fraction f1 = Fraction(1, 2) + 1;
. So as you would assume I'm a bit confused. Is the book just plain wrong or am I missing something crucial?