Looks like it might be the fact that you're accepting const rat &r1
but by sending data from the istream
you would be changing r1
. You can't change constants. Not sure if this is the issue but that's the first obvious thing that came to mind.
Try this:
istream& operator >> (istream &is, rat &r1)
{
is >> r1.num;
is >> r1.denom;
return is;
}
Don't forget to change your definition in the class:
friend istream& operator >> (istream&, rat&);