why can't << operator be overloaded as a member function is it because that is the way c++ is written and you just can't or is there another reason because I'm confused.
why can't << operator be overloaded as a member function is it because that is the way c++ is written and you just can't or is there another reason because I'm confused.
It can, unless you want to provide an overload which has its left operand of a different type (e.g., std::ostream). The reason is that implementing it as a member implies that its left operand is of the same class type as the class which it is declared in.
Another example is implementing a custom stream insertion operator for your own type. You obviously can't do that by declaring a operator<<() inside the definition of the stream -- you can't change that class, you don't own it.
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}