1

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

strictly speaking, you don't need the #define, an integer constant is just a plain number, after all... but if you want to use a name, it needs to be a #define.
True - I was going from an assumption that OP wanted to use the symbolic names for a reason.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.