Why is it not possible to overload the ternary operator?

前端 未结 5 1706
时光说笑
时光说笑 2020-12-05 14:39

Why is it not possible to overload the ternary operator \' ?: \'?

I use the ternary operator often to consolidate if statements, and am curious why the language desi

5条回答
  •  旧时难觅i
    2020-12-05 15:21

    For the same reason why you really should not (although you can) overload && or || operators - doing so would disable short-circuiting on those operators (evaluating only the necessary part and not everything), which can lead to severe complications.

提交回复
热议问题