![](https://seccdn.libravatar.org/avatar/a1e371f988a78da92c11c24b8b586b2e.jpg?s=120&d=mm&r=g)
Alle 15:46, mercoledì 25 dicembre 2002, Jerry Feldman ha scritto:
I am defining a template class, and am having trouble with defining the << operator for that class, for example: template <class Type> class Foo { public: // ... constructors, destructor et. al friend ostream & operator<<(ostream &, const Foo<Type> &); // here g++ generates the following warning: warning: friend declaration `class ostream & operator <<(ostream &, const Foo<Type> &)' warning: declares a non-template function
Declare it like a template as you did below. Of course add the keyword "friend". I tried it with the Suse 8 (gcc 2.95.x) compiler with no problem at all.
// ... rest of Foo };
// And the implementation template <class Type> ostream &operator<<(ostream &os, const Foo<Type> &foo) { os << foo; }
1) This function is missing something to return (usually return os;) 2) This function recursively call itself (and it will never stop) Is this just to make us see how you defined the function?