问题
#define MAX 100
double velocity[MAX];
for (itr = 0; itr < velocity[0]; itr = itr + 1)
{
velocity[itr] = velocity[0] - (1*itr);
distance[itr] = rk4_solve(itr, velocity);
cout << setw(5) << itr << setw(9) << velocity[itr] << setprecision(4) << setw(10) << distance[itr] << endl;
}
I am trying to input values into the array but for some reason I get the error: i Invalid types 'double [100][double]' for array subscript for the 3 lines inside the for loop.
回答1:
itr
must be an int
(or other integer type)
Be aware that you are comparing itr
with velocity[0]
in the for cycle (itr < velocity[0];
). You probably meant itr < MAX
, and I hope somewhere you defined the variable itr
回答2:
A total shot in the dark, but could you be missing a semicolon just above the lines shown?
回答3:
Just had a similar issue.
Array index's cannot be double or float.
I fixed my issue by typecasting the index's to int.
来源:https://stackoverflow.com/questions/7860439/invalid-types-double-100double-for-array-subscript