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
// ... rest of Foo
};
// And the implementation
template <class Type>
ostream &operator<<(ostream &os, const Foo<Type> &foo)
{
os << foo;
}
I've tried a few different ways of doing this. Of course I can simply
define my own member function (print), but I prefer the class to overload
the output operator.
--
Jerry Feldman