I have this example on class templates and friends:
template <typename T>
class Foo;
template <typename T>
std::ostream& operator<<(std::ostream&, Foo<T> const&);
template <typename T>
std::istream& operator>>(std::istream&, Foo<T>&);
template <typename T>
class Foo{
private:
int x = 10;
friend std::ostream& operator<< <T>(std::ostream&, Foo const&);
friend std::istream& operator>> <>(std::istream&, Foo&);
};
template <typename T>
std::ostream& operator<<(std::ostream& os, Foo<T> const& f){
return os << f.x;
}
template <typename T>
std::istream& operator>>(std::istream& is, Foo<T>& f){
return is >> f.x;
}
int main(){
Foo<double> fd;
std::cin >> fd;
std::cout << fd << '\n';
std::cout << '\n';
}
The wroks fine but I want to know the difference between the insertion operator
<<
friendship type and the extraction operator>>
friendship type to classFoo
.Does
...operator<< <T>..
that each instantiation of the output operator for the same type used to instantiateFoo
is its friend? So Is this One-To-One friendship?What confuses me is the extraction operator:
operator >> <>(...
: What does this mean? Is this a full specialization?