我试图使输出运算符重载,以使用带有非类型值的模板从类中进行打印。但是,我不断收到错误消息
在操作员功能体内的“意外的令牌'标识符',预期为';'”
。如何解决我的好友声明或运算符重载定义以避免这种错误?
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;
}
答案 0 :(得分:1)
您忘记了<<
// ..................VV
os << a.width << ":" << a.height;