It sounds like what you want is for your debug
and info
functions to return something like a std::stringstream
that will support operator<<
, but somehow also flush the output afterwards. If that's it, you would be better off using something like a variadic template function.
As for your other issue, std::endl
is actually a template, so its type cannot be used as T
for Log::operator<< <T> (T)
. This is one example of why it's not worth trying to reimplement the stream functionality. The overload which lets you write << std::endl
is declared something like template <class _CharT, class _Traits> basic_ostream<_CharT, _Traits> & operator<<(basic_ostream<_CharT, _Traits>&, basic_ostream<_CharT, _Traits> &(basic_ostream<_CharT, _Traits> &))
. std::endl
is a function template which takes an ostream, appends a newline, and flushes the stream.
I should also note that your debug
and info
functions are not returning a value. If you're using GCC, the warning for this is disabled by default but it can be a very tricky source of undefined behavior. Use -Wreturn-type
to enable it when you build something important.