initialize array size from another array value

后端 未结 3 1470
难免孤独
难免孤独 2020-12-18 09:48
#include 
using namespace std; 

const int vals[] = {0, 1, 2, 3, 4}; 

int newArray[ vals[2] ]; //\"error: array bound is not an integer constant\"

         


        
3条回答
  •  遥遥无期
    2020-12-18 10:21

    The C++ compiler can only allocate an array with a size known at compile time. If you want to allocated a variable size piece of memory, use the new operator.

提交回复
热议问题