我正在尝试重载operator<<
类模板,如下所示:
template<int V1,int V2>
class Screen
{
template<int T1,int T2> friend ostream& operator<< (ostream &,Screen<T1,T2>&);
private:
int width;
int length;
public:
Screen():width(V1),length(V2){}
};
template<int T1,int T2>
ostream& operator<< (ostream &os,Screen<T1,T2> &screen)
{
os << screen.width << ' ' << screen.length;
return os;
}
上面的代码运行正确!但我想知道是否有任何方法可以operator<<
通过不将其设置为函数模板来以某种方式重载:
friend ostream& operator<< (ostream &,Screen<T1,T2>&);
?