1

I have the error I mentioned in the title on this part of my code.

component_t *buffer = new component_t[3 * width*height];
component_t getRawDataPtr();

...
    for (unsigned int i = 0; i < width*height * 3; i = i + 3) {
        file.read((char *)cR, sizeof(char));
        file.read((char *)cG, sizeof(char));
        file.read((char *)cB, sizeof(char));
        buffer[i] = cR / 255.0f;
        buffer[i + 1] = cG / 255.0f;
        buffer[i + 2] = cB / 255.0f;
    }
    file.close();

    image->setData(buffer);

...

void Image::setData(const component_t * & data_ptr) {
    if (height == 0 || width == 0 || buffer == nullptr)
        return;
    for (unsigned int i = 0; i < height*width * 3; i++)
        buffer[i] = data_ptr[i];
}

I tried image->setData(*buffer) or image->setData(&buffer) but that didn't work either. If anyone knows how to fix this I'd appreciate it. Thanks in advance.

4

2 回答 2

0

您可以更改:

void Image::setData(const component_t * & data_ptr) {

至:

void Image::setData(const component_t * data_ptr) {

或者:

image->setData(buffer);

const component_t *cbuffer = buffer;
image->setData(cbuffer);
于 2016-11-24T21:02:07.537 回答
0

您尝试将 const 指针分配给非常量指针

buffer[i] = data_ptr[i];

这是不允许的,因为这会违反 const 的承诺data_ptr

于 2016-11-24T21:02:13.357 回答