Yes.. yes.. i know this topic has been covered many times..
I've looked through other posts but cannot find the solution i am looking for.. here is my problem:
Code:
int main()
{
Rational result;
cout << result;
return 0;
}
Code:
class Rational
{
public:
Rational();
friend ostream &operator<<(ostream &out, Rational &c);
private:
int numerator, denominator;
};
Rational::Rational()
{
numerator = 0;
denominator = 1;
}
ostream &operator<<(ostream &out, Rational &c)
{
out << c.numerator << "/" << c.denominator;
return out;
}
someone want to tell me what i'm doin' wrong?
shouldn't 0/1 be outputed to the screen?
i understand overloading operators but this is the first time i've ever tried to overload the '<<' operator.
compiler is giving me following errors:
friends must be functions or classes.
declaration missing ;
declaration does not specify a tag or identifier.
Declaration syntax error.
Undefined symbol cout.
This is not my entire code.. but i believe i've supplied enough info..
so any ideas what i am doing wrong?