I'm trying to define a stack c-style array whose size is taken from const array and is known in compile-time.
const int size[2]={100, 100};
int ar[size[0]]; //error: expression must have a constant value
It fails. How it can be fixed?
I'm trying to define a stack c-style array whose size is taken from const array and is known in compile-time.
const int size[2]={100, 100};
int ar[size[0]]; //error: expression must have a constant value
It fails. How it can be fixed?
"array whose size is taken from const array and is known in compile-time"
With C++11 you can have :
constexpr int size[2]={100, 100}; // size[0] is Compile-time constant
Use -std=c++11 or -std=c++0x to compile
constexpr to use array elements as compile-time constants - and that wasn't available before 2011.Some options (with varying degrees of popularity):
const int (C99 or newer or C++)enumC++ array sizes must be constant expressions, not just constant data. Array data, even though const, is not a constant expression.