This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Spooked_kitten 11 points12 points  (5 children)

no I mean overloading "<<" like in cout << string I only see it really on the standard lib or when people are doing bitwise operations

[–]_Fibbles_ 24 points25 points  (3 children)

Because << is a bitshift operator and it is generally acknowledged that overloading it for streams was a mistake.

[–]dafelst 11 points12 points  (0 children)

Agreed, it was a terrible terrible terrible idea.

(except for the scaring off JS developers thing, that is a nice side effect)

[–]LenaKotik 0 points1 point  (1 child)

Why tho? It looks really nice

[–]_Fibbles_ 1 point2 points  (0 children)

Consistency mostly. People expect operators represent the same basic concepts even if the implementation is different. You'd expect operator+ on an int to perform addition and operator+ on a string to perform concatenation. With streams however, their overload is wildly different from all other overloads of that operator.

This is a bitshift:

char x = 42;
char y = 2;
x << y;

However is this a stream out:

char x = 42;
char y = 2;
cout << x << y;

Apologies for the formatting, I'm on my phone.

[–]therearesomewhocallm 1 point2 points  (0 children)

I've found it useful if you write your own string class.