且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C ++ - 如何声明一个类模板的函数模板朋友

更新时间:2022-01-29 22:25:59

c $ c> friend 作为函数模板如果你想匹配你定义的:

You have to declare friend as a function template if you want to match the one you defined:

template <typename U> // use U, so it doesn't *** with T
friend ostream& operator<<(ostream& os, MyVector<U> vt);

如果 friend 为类模板声明,不会使其成为函数模板。

If a friend function is declared for a class template, that does not make it a function template.