Dark Bit Factory & Gravity
PROGRAMMING => C / C++ /C# => Topic started by: Clyde on October 06, 2009
-
Hiya!
im having the error message error C2108: subscript is not of integral type with using the following code inside a loop.
int value1=34;
float XR[ 3 ];
float slut_c[360];
float x_cord[100];
float x1,y1;
for ( int a=0; a<100; a++)
{
x1=x_cord[a]; //example 1
y1=y1*slut_c[ XR[ value1 ] ];
}//next
-
"XR[value1]" contains a float.
You need a cast to use it as an index:
y1=y1*slut_c[ (int)XR[ value1 ] ];
-
Cheers dude!
So because an array no matter what kind of scope it has, as inside the brackets an array is an integer, it requires an (int) conversion?
-
Yeah, the index for an array (the bit inside the brackets) has to be an integer type (signed or unsigned) char, short, int, long, long long, not float, double or long double.
Jim
-
It's for allowing things like this (float index for array) that give basic compilers bad reputation. I didn't believe freebasic would allow it but it did, without any warning :(