I am trying to overload the output operator to print from a class with a template that uses non-type values. However, I keep getting the error
"unexpected token 'identifier', expected ';'"
in the operator's function body. How do I fix either my friend declaration or my operator overload definition to avoid this error?
template <int N, int M> class Screen {
friend std::ostream& operator<< (std::ostream&, const Screen&);
public:
Screen(): width(N), height(M) {}
int width = 0;
int height = 0;
};
template <int N, int M>
std::ostream& operator<< (std::ostream& os, const Screen<N, M>& a)
{
os << a.width << ":" a.height;
return os;
}
You have forgotten a
<<