+ 1

Can compile-time constants be given values involving sizeof()?

Would something like const int kVar1 = sizeof(int) * 4; be considered a compile-time constant?

28th Aug 2017, 6:58 AM
R- Ry
R- Ry - avatar
3 Respostas
+ 10
sizeof is a compile time operator.
28th Aug 2017, 7:08 AM
jay
jay - avatar
+ 4
Yes. In this case constexpr should be used instead of const. constexpr is a const compile time expression
28th Aug 2017, 9:52 AM
aklex
aklex - avatar
+ 2
if it compile, then yes
28th Aug 2017, 7:02 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar