Using const int as array size

前端 未结 5 690
太阳男子
太阳男子 2020-12-21 18:59

Why am I able to use a locally declared const int as the size of an array declaration but am not allowed to do the same with a const int passed as

5条回答
  •  时光取名叫无心
    2020-12-21 19:51

    Since c++11 though you can use constexpr which would do what you expect. The constexpr says compiler that apart the variable is const its value can be evaluated at compile time. See: http://en.cppreference.com/w/cpp/language/constexpr

提交回复
热议问题