I have a friend function that overloads the insertion operator to deal with class objects.
I'm confused because I'm not sure how it takes its parameter.
Here's the code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
std::ostream& operator<<(std::ostream &stream, Rational rhs){
stream << rhs.numerator << "/" << rhs.denominator ;
return stream;
}
// one of my overloaded operator functions..
Rational Rational::operator+(int rhs){
int tempN = (rhs * denominator) + numerator;
int tempD = denominator;
return Rational(tempN, tempD);//if this is my return, how is it passed in
}
Is my return in the + function incorrect, or can that work somehow?
Thank you.
**edit
I should point out that I can't mess with the declaration of the functions. Just the code inside.
> I'm not sure how it takes its parameter. std::ostream& operator<<(std::ostream &stream, Rational rhs)
`rhs' is passed by copy, ¿is that what you're asking?
> t I can't mess with the implementation of the functions. Just the code inside.
the implementation is the code inside...