Can't set variable length with variable

前端 未结 5 1292
梦如初夏
梦如初夏 2021-01-14 14:40

What I\'m trying to do right now is to create an array with a length that is defined by a variable. However, when I put the variable in the array length, it gives me a \"Va

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-14 15:09

    You cannot have variable length arrays(VLA) in standard C++.
    Variable length arrays are not allowed by the C++ Standard. In C++ the length of the array needs to be a compile time constant. Some compilers do support VLA as a compiler extension, but using them makes your code non-portable across other compilers.

    You can use, std::vector instead of an VLA.

提交回复
热议问题