Invalid types 'double [100][double]' for array subscript

匿名 (未验证) 提交于 2019-12-03 02:38:01

问题:

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!