<>中的一个问题!!!
jp311 2002-08-17 08:09:46 小弟我看<<C++ primer>>,看到了16.4(P682)讲的是类模板的友元声明
2.绑定的友元类模板或函数模板
说一个友元(也是模板实例)如果要和类模板形成一对一的映射就应该如下定义
template<class type>
class testclass {
friend void fun<type>(testclass<type> &a);
...
};
template<class type>
void fun(testclass<type>);
可是书后面接着讲了一个例子,是重载operator<<的,也是声明成了绑定的友元函数模板可是只写成
template<class type>
class testclass {
friend ostream &operator<<(ostream &, const testclss<type> &);
...
}
我觉的不妥,于是在DEV-C++下写了一个测试,果然编不过去,于是改成
friend ostream &operator<<<type>(ostream &, const testclss<type> &);
编译通过,运行正常...
不知道那个定义是正确,望高人指教