【发布时间】:2018-10-06 19:01:17
【问题描述】:
我正在尝试重载输出运算符以从具有使用非类型值的模板的类中打印。但是,我不断收到错误
“意外的令牌'标识符',预期的';'”
在操作符的函数体中。如何修复我的朋友声明或运算符重载定义以避免此错误?
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;
}
【问题讨论】:
标签: c++ templates operator-overloading non-type