• Welcome to Dark Bit Factory & Gravity.
 

[C++] error C2108: subscript is not of integral type.

Started by Clyde, October 06, 2009

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

Clyde

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
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

hellfire

"XR[value1]" contains a float.
You need a cast to use it as an index:
y1=y1*slut_c[ (int)XR[ value1 ] ];
Challenge Trophies Won:

Clyde

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?
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Jim

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
Challenge Trophies Won:

Rbz

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 :(
Challenge Trophies Won: