Are multiple conditional operators in this situation a good idea?

前端 未结 21 2910
名媛妹妹
名媛妹妹 2020-12-15 06:23

I just saw this block of code on the Wikipedia article on conditional operators:

Vehicle new_vehicle = arg == \'B\' ? bus      :
                      arg ==         


        
21条回答
  •  心在旅途
    2020-12-15 07:19

    Read the C++ section of the Wikipedia article a bit more carefully. It explicitly lists some situations where using the ?: operator is the only option, and can't be replaced by if/else or switch.

    On the other hand, I wouldn't use it only because it looks prettier.

提交回复
热议问题