为什么我不能使用相同的模板参数为一个模板参数的朋友函数?我的意思是下面的代码是可以的!运营商<<(ostream&os,...)模板类
template <class Vertex>
class Edge
{
template <class T>
friend ostream& operator<<(ostream& os, const Edge<T>& e);
/// ...
};
template <class T>
ostream& operator<<(ostream& os, const Edge<T>& e)
{
return os << e.getVertex1() << " -> " << e.getVertex2();
}
但这一个是不好的。为什么?问题是什么? (我得到链接错误。)
template <class Vertex>
class Edge
{
friend ostream& operator<<(ostream& os, const Edge<Vertex>& e);
/// ...
};
template <class T>
ostream& operator<<(ostream& os, const Edge<T>& e)
{
return os << e.getVertex1() << " -> " << e.getVertex2();
}
一个朋友是一个模板,另一个是不。 – Xeo 2013-04-22 09:20:05