The reason is that the compiler cannot deduce the type of T
, because std::endl
is a function template defined as
template <class charT, class traits>
basic_ostream<charT,traits>& endl ( basic_ostream<charT,traits>& os );
The way it is overcome in IOStreams is by providing an appropriate overload of operator<<
:
OutputStream& operator <<(std::ostream& ( *pf )(std::ostream&))
{
cout << pf;
return *this;
}