我有我在代码的这部分标题中提到的错误。错误C2664:无法将参数1从'imaging :: component_t *'转换为'const imaging :: component_t *''
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];
}
我试过图像 - >使用setData(*缓冲区)或图像 - >使用setData(&缓存),但也不能工作。如果有人知道如何解决这个问题,我会很感激。 在此先感谢。
如果你想传递一个const引用给指针,它的格式为'component_t * const&'。不是通过引用传递是一个好主意。 –