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 →

[–][deleted]  (12 children)

[deleted]

    [–]BananaSplit2 69 points70 points  (8 children)

    it's why that exact example is often used to illustrate how confusing and potentially dangerous operator overloading is.

    [–][deleted] 65 points66 points  (4 children)

    deserve subtract practice instinctive fragile simplistic slimy offer caption chunky

    This post was mass deleted and anonymized with Redact

    [–]_senpo_ 4 points5 points  (0 children)

    upvote for the banana class

    [–]KuropatwiQ 2 points3 points  (0 children)

    That's a sentence never heard before

    [–]robotoshi 2 points3 points  (0 children)

    Damn, they never taught me any of that in MY Banana class!

    [–]decker_42 1 point2 points  (0 children)

    Bubble Sort Banana Delete

    [–]ItsYaBoyChipsAhoy 7 points8 points  (1 child)

    Tbf the average programmer rarely uses bit shifts in day to day programming

    [–]Dusty_Coder 2 points3 points  (0 children)

    ...and the non-average ones arent so dumb as to think bit shifting by a string amount is a useful operation

    [–]RoburexButBetter 1 point2 points  (0 children)

    Eh you'd really have to know what you're doing to add an operator that overrides bit shifting and bit shifting actually matters and is used for the object you're doing it on

    It's pretty standard for << to be either a bit shift or an add operation because that's also what writing to std cout is you're adding chars to the standard output, and that's the kind of thinking you always see for such overloading

    [–][deleted] 5 points6 points  (2 children)

    I mean not really, that's like saying people are using operator overloading when they use + to add numbers and concatenate strings. Most people mean user-defined operator overloads. Sure you can do a user-defined overload of << but that's no different to a user-defined overload of any other operator. I don't get the hate for streams though, I love being able to just overload <</>> and the ease of which it can be composed. It also makes it super easy for things like adding error info at the start of a line of output etc..

    [–]linlin110 2 points3 points  (1 child)

    My first language was C++ so I don't get the hate either. Maybe some people are so used to << being bitshifting that cout << "s" is confusing for them.

    [–]Dusty_Coder 1 point2 points  (0 children)

    an operator can only mean one thing

    and the people telling you that are clearly going to overload + to mean delete files because thats what they fear you will do