Jump to content
  • Advertisement
Sign in to follow this  

invalid types for array subscript (double)

This topic is 3157 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:

when i try and get the value of

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!