我有我在代碼的這部分標題中提到的錯誤。錯誤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&'。不是通過引用傳遞是一個好主意。 –