哈蛤哈 发表于 2019-6-4 08:48:08

此错误应如何修改?

error:invalid types 'float' ' for array subscript

float propensity_granularity(float a, float b, float c)
{
    float table =
    {
      {{0.0,0.0,0.0}, {0.0,0.0,0.1}, {0.1,0.1,0.2}},
      {{0.1,0.1,0.2}, {0.2,0.3,0.4}, {0.4,0.5,0.6}},
      {{0.4,0.5,0.6}, {0.5,0.6,0.7}, {0.8,0.9,1.0}},
      {{0.9,0.9,1.0}, {1.0,1.0,1.0}, {1.0,1.0,1.0}}
    };
        return table;
}

BngThea 发表于 2019-6-4 08:51:11

下标索引不能是float类型,应该用unsigned int

哈蛤哈 发表于 2019-6-4 09:09:29

BngThea 发表于 2019-6-4 08:51
下标索引不能是float类型,应该用unsigned int

把table443前边的float改成unsigned int还是报错啊。小白一个,求指教

VisionSo 发表于 2019-6-4 09:19:28

哈蛤哈 发表于 2019-6-4 09:09
把table443前边的float改成unsigned int还是报错啊。小白一个,求指教

他说的是括号里的形参a,b,c

shake_a_tree@16 发表于 2019-6-4 09:22:14

float propensity_granularity(int a, int b, int c)
{
        float table =
        {
                {{0.0,0.0,0.0}, {0.0,0.0,0.1}, {0.1,0.1,0.2}},
                {{0.1,0.1,0.2}, {0.2,0.3,0.4}, {0.4,0.5,0.6}},
                {{0.4,0.5,0.6}, {0.5,0.6,0.7}, {0.8,0.9,1.0}},
                {{0.9,0.9,1.0}, {1.0,1.0,1.0}, {1.0,1.0,1.0}}
        };
        return table;
}

int main()
{
        float aa = propensity_granularity(2, 2, 1);
        printf("%f", aa);
}

哈蛤哈 发表于 2019-6-4 09:26:38

VisionSo 发表于 2019-6-4 09:19
他说的是括号里的形参a,b,c

明白了
页: [1]
查看完整版本: 此错误应如何修改?