我的问题与一个this有关。模板定义中的朋友函数
我想重载操作< <一些类和我发现了两个不同的符号,这两个工作:
template <class T>
class A{
T t;
public:
A(T init) : t(init){}
friend ostream& operator<< <> (ostream &os, const A<T> &a); //need forward declaration
//template <class U> friend ostream& operator<< (ostream &os, const A<U> &a);
};
难道我定义具有不同的符号一样的东西?或者是第一个更严格的版本,在哪个实例中(在这种情况下,只有与我的A类相同T的实例)< <是A的朋友?
几件事。首先,我认为你的意思是'os << b.t'而不是'os << b.i'来输出拥有的成员变量。其次,上面的例子可以使用operator << instance,因为它使用的是'ostreame&operator <<(ostream&os,double num)'函数,而不是声明的模板版本。 – workmad3 2010-01-16 10:03:35
我的头似乎在其他地方 - 但在平均时间修复它。 – 2010-01-16 10:04:48