I saw the following implementation of the operator* as follows:
class Rational {
public:
Rational(int numerator=0, int denominator=1);
...
private:
int n, d; // numerator and denominator
friend const Rational operator*(const Rational& lhs, const Rational& rhs)
{
return Rational(lhs.n * rhs.n, lhs.d * rhs.d);
}
};
I have two questions here:
- Q1> why the operator* has to return const Rational rather than simply Rational
- Q2> when we define a friend function, should we care about the access modifier?