I have a class called fraction, and I'm declaring some operators as friends. I declared the friend operators beforehand, as http://www.parashift.com/c++-faq-lite/templates.html#faq-35.16 told me to do, but it only fixed +, -, *, and /. << and >> still don't work.
template <class T> class Fraction;
template <class T> Fraction<T> operator+ (Fraction<T> const& left, Fraction<T> const& right);
template <class T> Fraction<T> operator- (Fraction<T> const& left, Fraction<T> const& right);
template <class T> Fraction<T> operator* (Fraction<T> const& left, Fraction<T> const& right);
template <class T> Fraction<T> operator/ (Fraction<T> const& left, Fraction<T> const& right);
template <class T> ostream& operator<< (const ostream& output, Fraction<T> const& value);
template <class T> istream& operator>> (const ostream& input, Fraction<T> const& value);
And the class:
template <class T>
class Fraction
{
...
friend Fraction<T> operator+ <>(const Fraction<T>& left, const Fraction<T>& right);
friend Fraction<T> operator- <>(const Fraction<T>& left, const Fraction<T>& right);
friend Fraction<T> operator* <>(const Fraction<T>& left, const Fraction<T>& right);
friend Fraction<T> operator/ <>(const Fraction<T>& left, const Fraction<T>& right);
friend ostream& operator<< <>(const ostream& output, const Fraction<T> value);
friend istream& operator>> <>(const istream& input, Fraction<T> value);
}
template <class T> ostream& operator<< <>(const ostream& output, const Fraction<T>& value)
{
output << value.Numerator << '/' << value.Denominator;
return output;
}
template <class T> istream& operator>> <>(const istream& input, Fraction<T>& value)
{
T n, d, char seperator;
cin >> n >> seperator >> d;
value.SetNumerator(n);
value.SetDenominator(d);
return input;
}