Rational class:
1、member函数实现:
2、non-member函数实现:
针对以下代码:
Rational oneHalf(1,2);
Rational result = oneHalf * oneEighth;
result = oneHalf * 2; //1与2都没错误
result = 2 * oneHalf; //1错误,2很好
Rational class:
1、member函数实现:
2、non-member函数实现:
针对以下代码:
Rational oneHalf(1,2);
Rational result = oneHalf * oneEighth;
result = oneHalf * 2; //1与2都没错误
result = 2 * oneHalf; //1错误,2很好