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

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

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -