产生错误“表达式必须是可修改的左值”

时间:2017-10-24 07:35:00

标签: c++

我在第channels[0][x] = luma_lut[row[x]];行的代码中遇到了最大错误:

typedef struct {
    const unsigned char *const *const row_pointers;
    float gamma_lut[256];
} image_data;
void convert_image_row_gray(const float * __restrict channels[], const int num_channels, const int y, const int width, void * user_data)
{
    image_data *im = (image_data*)user_data;
    const unsigned char *row = im->row_pointers[y];
    const float *luma_lut = im->gamma_lut; // init converts it

    for (int x = 0; x < width; x++) {
        channels[0][x] = luma_lut[row[x]];
    }
}

此代码有什么问题?

1 个答案:

答案 0 :(得分:1)

channelsconst float **类型声明,这意味着channels[i][j]const float类型的左值。您不能更改const float左值 - 它们是const

鉴于此channels声明您可以更改channels本身,您可以更改channels[i],但不能更改channels[i][j]