C ++ faq 35.16
http://www.parashift.com/c++-faq-lite/template-friends.html
#include <iostream>
template<typename T>
class Foo {
public:
Foo(T const& value = T());
friend Foo<T> operator+ (const Foo<T>& lhs, const Foo<T>& rhs);
friend std::ostream& operator<< (std::ostream& o, const Foo<T>& x);
private:
T value_;
};
The author claims:
'Capture occurs when the compiler sees the lines of friends in the correct class definition. At this moment, he still does not know that the friend’s functions are templates themselves (why this? Are the template template functions not the default template?) ; he suggests that they are not patterns: "
Foo<int> operator+ (const Foo<int>& lhs, const Foo<int>& rhs)
{ ... }
std::ostream& operator<< (std::ostream& o, const Foo<int>& x)
{ ... }
Why are the above not templates? are these patterns that are created via int?
' + < < , , , "undefined " , .
, , , :
template<typename T> class Foo;
template<typename T> Foo<T> operator+ (const Foo<T>& lhs, const Foo<T>& rhs);
template<typename T> std::ostream& operator<< (std::ostream& o, const Foo<T>& x);
- ? , Foo, T "int" .
.