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

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -