user2253513
user2253513

Reputation:

Error: Array bound not integer constant in Header

I have 2D arrays in header files, for which I declared the sizes of both:

    int numPaths = 2;
    int pathLength = 11;
    double x[numPaths][pathLength] = {{62, 114, 0, 73, 55, 21, -28, -93, 0, 0, 0},{-90, 208, 0, 4, 7, 10, 12, 13, 11, -198, -147}};
    double y[numPaths][pathLength] = {{55, 88, 0, -42, 12, 45, 54, 40, 0, 0, 0},{269, -117, 0, -10, -14, -17, -20, -24, -69, -82, 20}};

I get this error: Array bound not an integer constant.

My 2D arrays are not dynamically changes, and I've declared the sizes of these arrays (numPaths and pathLength). I'm not sure what the problem is?

Upvotes: 1

Views: 117

Answers (1)

Carl Norum
Carl Norum

Reputation: 224864

numPaths and pathLength aren't constants, just like the error message says. You need:

#define numPaths 2
#define pathLength 11

Some compilers will let you get away with:

const int numPaths = 2;
const int pathLength = 11;

As an extension.

Upvotes: 1

Related Questions