c++ - Expected constant in 2d array -
double rainpermonth(const int years) { int monthyear[months][years]; // ... }
visual studio shows squiggly line underneath array declaration, saying years
must constant when i'm creating array. ide issue because variable has yet initialized, or writing incorrectly?
months
declared globally.
an array size must constant expression - is, value known @ compile time. (some compilers offer c-style variable-length arrays non-standard extension, don't think visual c++ does. if does, it's better not rely on such extensions.)
a function argument isn't known @ compile time, can't used array size. best option here probably
std::vector<std::array<int, months>> monthyear(years);
Comments
Post a Comment