I am trying to use the istream
function below to access the private data members numerator and denominator, however, I am getting errors about it being private. istream
is a non-friend, non-member function (I cannot make it a friend). I understand that I cannot directly access the private members, but shouldn't my reference to MyFraction
allow me to?
std::istream & operator>>(std::istream & sin, MyFraction & frac)
{
return sin >> frac.numerator >> frac.denominator;
}
I have getters (getNumerator()
and getDenominator()
), however, I cannot access the members that way either. I also get an error:
ambiguous overload for operator>>.
My getters do return by value:
inline int MyFraction::getNumerator() const
{
return numerator;
}
inline unsigned int MyFraction::getDenominator() const
{
return denominator;
}
What am I overlooking in this function?