c++ - Stream Operator Overloading -


why should overloading of stream operators(<<,>>) kept friends rather making them members of class?

when overload binary operator member function of class overload used when first operand of class type.

for stream operators, first operand stream , not (usually) custom class.

for reason overloaded stream operators custom classes designed used in conventional manner can't member functions of custom class, must free functions.

(i'm assuming stream classes not open changed; if add member functions stream classes cope additional custom types undesirable dependency point of view.)

whether or not friends should depend on whether need access non-public members of class.


Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -