vineoff said:
Why operator== i.e. can be declared as member function but operator<<
can't?
This is an FAQ:
http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.8
It's not that you can't declare operator<<() as a member function, it's
that it wouldn't do what you seem to think it would.
In short, to declare operator<<() as a member function, you would have
to modify the declaration and definition of class std:
stream, since
the left-hand-side parameter is of type std:
stream and the
right-hand-side parameter is the object you want to send to the
ostream. And of course, you are not permitted to modify std:
stream
yourself.
If you, on the other hand, made operator<<() a member of your class
Foo, then you would have to put Foo on the left-hand-side and the
std:
stream on the right-hand-side when you used the operator, which
would look very strange.
Best regards,
Tom