1

I was always curious about that, but never found a solid answer or an easy to understand explanation. I have tried with other operators and it works just fine. This operator in particular is an interesting one. I just can't get my head wrap around it.

  • All I got from that answer was an assumption that it was abandoned and no real reason was given as to why it wasn't done. I am looking for the origin story of this operator. –  Oct 05 '17 at 10:15

1 Answers1

4

FAQ of stroustrup :

There is no fundamental reason to disallow overloading of ?:. I just didn't see the need to introduce the special case of overloading a ternary operator. Note that a function overloading expr1?expr2:expr3 would not be able to guarantee that only one of expr2 and expr3 was executed.

msc
  • 33,420
  • 29
  • 119
  • 214
  • 1
    This is a much better answer than the one before. So basically no one knows and didn't bother messing with the idea. –  Oct 05 '17 at 10:17
  • 1
    @MSquared That's not a good reason to re-ask the question though. While this answer may be better than ones at the dupe, scattering good answers across multiple identical questions is exactly what the dupe system is supposed to avoid because it makes it harder to find all the good answers. If you think an existing question needs better answers, you should raise a bounty (requires 75 rep) so SO stays nice and searchable. – Baum mit Augen Oct 05 '17 at 10:31
  • but on the other hand, `&&` and `||` can be overloaded, so short-circuit evaluation is not the reason. – YumeYao Jul 20 '21 at 06:24