0

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;
}

1 Answer 1

1

You have forgotten a <<

// ..................VV
os << a.width << ":" << a.height;
1
  • 1
    @MildMax - Things that happen.
    – max66
    Commented Oct 6, 2018 at 19:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.