Sign in to follow this  

invalid types for array subscript (double)

This topic is 2846 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i have an array which is a double
double map[8][8];

i have two double values which represent x and y grid coordinates
double x;
double y;

the reason why they are doubles is because they are rounded down from another variable like so:
x=floor(Ay/64);

when i try and get the value of
map[x][y];

i get the error: 40 main.cpp invalid types `double[8][8][double]' for array subscript why?

Share this post


Link to post
Share on other sites
you are confusing the subscripts with the values AT the subscripts ... when you declare an "8x8 two dimensional array of doubles" you have created a sections of memory which holds 64 double values, which can be accessed with the integers 0-7 in each of the subscripts ... so map[0][0] is the first element (and is of type double) and map[7][7] is the last element (of type double).

if you are using a double to locate WHERE in the map you are (because of math functions), you must convert that number to an int BEFORE using it as a subscript ... either by rounding, truncating, etc.

so remember, the type you want to find inside of the array is the type of the array ... the type of the subscript is always integral (as mentioned already).

Share this post


Link to post
Share on other sites

This topic is 2846 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this