On Mon, 26 Apr 2004 15:43:20 -0400 in comp.lang.c++, TJ <> wrote,
I've been referring to many codes and books and always see that the
stream insertion operators are overloaded as friends. Why is that?
This and several related issues are covered in section 15 of Marshall
Cline's C++ FAQ. It is always good to check the FAQ before posting.
You can get the FAQ at:
http://www.parashift.com/c++-faq-lite/
I disagree quite a bit with the FAQ on this. I like the public member
"printon()" function and standalone non-friend inline operator>>().
printon() may or may not be virtual, as your requirements dictate, but
most often it probably is. The claim that people are not supposed to
call printon() is baloney.
Take your choice.