constexpr vs const vs constexpr const

前端 未结 3 1263
小鲜肉
小鲜肉 2021-01-14 13:41

const-vs-constexpr-on-variables

What the guy says about constexpr is right if double is used (or float of course). However, if you change t

3条回答
  •  自闭症患者
    2021-01-14 14:03

    From the comments it seems like OP is asking for Standard quote which defines const int as a compile-time constant, but const double as not.

    The corresponding details are found in 5.19, Constant Expressions. In particular:

    ...an lvalue-to-rvalue conversion (4.1) unless it is applied to a non-volatile glvalue of integral or enumeration type that refers to a non-volatile const object with a preceding initialization, initialized with a constant expression...

    int is an integral type, while double is not.

提交回复
热议问题