Why in conditional operator (?:), second and third operands must have the same type?

后端 未结 5 1498
挽巷
挽巷 2021-01-31 19:35

Why in conditional operator(?:), second and third operands must have the same type?

My code like this:

#include 

        
5条回答
  •  没有蜡笔的小新
    2021-01-31 19:52

    I wonder why they must have the same type?

    In C++ any expression must have a single type, and the compiler should be able to deduce it at compile time.

    This stems from the fact that C++ is a statically typed language wherein all types must be known at compile time.

提交回复
热议问题