I am trying to create a class that works with rational numbers and performing operator overloading on them. I am having issue on one part of the program, the input stream.
I am supposed to take input in the format "12/8" for example, and it should store 12 into a variable a and then 8 into a variable b.
Here is my code:
istream& operator>>( istream& In, Rational& Item )
{
char division_sign;
int a,b;
In >> a >> division_sign;
if (division_sign != '/' || !In.good())
{
In.setstate( ios::failbit );
}
else
{
In >> b;
if (b != 0 || !In.good())
{
return Item.numerator_ = a, Item.denominator_ = b;
}
}
}
And here is the error I receive:
In function 'std::istream& operator>>(std::istream&, Rational&)':
131: error: invalid initialization of reference of type 'std::istream&' from expression of type 'int'
Line 131
is the return
statement