• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# invalid types for array subscript (double)

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1copper103  Members

Posted 28 February 2010 - 03:04 AM

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?

### #2GregMichael  Members

Posted 28 February 2010 - 03:22 AM

Array subscripts need to be integers.

### #3copper103  Members

Posted 28 February 2010 - 03:26 AM

thanks for telling me

### #4Xai  Members

Posted 28 February 2010 - 03:27 AM

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).

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.