invalid types for array subscript (double)

Started by
2 comments, last by Xai 14 years, 1 month ago
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?
Advertisement
Array subscripts need to be integers.
thanks for telling me
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).

This topic is closed to new replies.

Advertisement