【问题标题】:Invalid types 'double [100][double]' for array subscript数组下标的无效类型“双 [100] [双]”
【发布时间】:2011-12-13 05:04:07
【问题描述】:
#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 Invalid types 'double [100][double]' for array subscript for the 3 lines for the for loop.

【问题讨论】:

    标签: c++ arrays types double


    【解决方案1】:

    刚刚遇到类似问题。

    数组索引不能是双精度或浮点数。

    我通过将索引类型转换为 int 解决了我的问题。

    【讨论】:

      【解决方案2】:

      完全是在黑暗中拍摄,但您会在显示的线条上方缺少一个分号吗?

      【讨论】:

        【解决方案3】:

        itr 必须是 int(或其他整数类型)

        请注意,您在 for 循环 (itr &lt; velocity[0];) 中将 itrvelocity[0] 进行比较。你的意思可能是itr &lt; MAX,我希望你在某个地方定义了变量itr

        【讨论】:

        • 我同意这个答案并想指出,如果不是这种情况,那么velocity[0] 是未定义的,所以在运行时可能会发生任何事情。
        • @Gorpik +1 考虑到他剪掉了多行代码,我不确定:-)
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-26
        • 2012-09-07
        • 2022-12-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多