The two functions that I posted (input and output) should be free functions (not members of the Rational class). You can simply insert them after the class declaration and before the main() function. Or, you can put them after the main function, but then, you have to insert the declarations between the Rational class declaration and the main function, as so:
class Rational {
//..
};
ostream& operator << (ostream& out, const Rational& rat); // declaration.
istream& operator >> (istream& in, Rational& rat); // declaration.
int main() {
//... ...
};
// then, somewhere here, insert the code I gave, verbatim.
The error message you got is because those functions should not be member functions of the Rational class, they must be free functions (outside the class, so, no Rational::
should appear).
And, remember to make the two get-functions const
as I said earlier. Otherwise, you'll get an error like this:
error: passing ‘const Rational’ as ‘this’ argument of ‘int Rational::getNumerator()’ discards qualifiers [-fpermissive]