나는 C++ 맵을 반복적으로 구현하는 ImageMatrix 클래스를 가지고있다. 최종 결과는 3 차원 배열입니다. (100) 말과를 법원에 값을 테스트하는 내가 값을 설정할 때왜 C++ 맵 구현에 값이 저장되지 않습니까?
ImageMatrixRow ImageMatrix::operator[](VInt32 rowIndex)
{
return rows[rowIndex];
}
ImageMatrixColumn ImageMatrixRow::operator[](VUInt32 columnIndex)
{
return columns[columnIndex];
}
VInt32 &ImageMatrixColumn::operator[](VUInt32 channelIndex)
{
return channels[channelIndex];
}
기본적으로, 그것은 0으로 표시 :
typedef uint32_t VUInt32;
typedef int32_t VInt32;
class ImageMatrix
{
public:
ImageMatrixRow operator[](VInt32 rowIndex)
private:
ImageMatrixRowMap rows;
};
typedef std::map <VUInt32, VInt32> ImageMatrixChannelMap;
class ImageMatrixColumn
{
public:
VInt32 &operator[](VUInt32 channelIndex);
private:
ImageMatrixChannelMap channels;
};
typedef std::map<VUInt32, ImageMatrixColumn> ImageMatrixColumnMap;
class ImageMatrixRow
{
public:
ImageMatrixColumn operator[](VUInt32 columnIndex);
private:
ImageMatrixColumnMap columns;
};
typedef std::map<VUInt32, ImageMatrixRow> ImageMatrixRowMap;
각 연산자는 간단히과 같이, 내지도 - 래퍼 클래스를 반환 , 그리고 내가 정한 숫자가 아닙니다.
for (VUInt32 a = 0; a < GetRowCount(); a++)
{
for (VUInt32 b = 0; b < GetColumnCount(); b++)
{
for (VUInt32 c = 0; c < GetChannelCount(); c++)
{
VInt32 value = 100;
matrix[a][b][c] = value;
VInt32 test = matrix[a][b][c];
// pixel = 100, test = 0 - why?
cout << pixel << "/" << test << endl;
}
}
}
주 : 더 적은 공간을 차지하도록 내가이 예를 들어 원래의 코드를 변경, 그래서 몇 가지 구문 오류가 (그들을 지적하지 마십시오) 발생할 수 있습니다.
그래, 그의 코드는 ImageMatrixColumn :: operator []에서 참조를 반환하기 위해 기억했기 때문에 우연히 컴파일됩니다. –
고마워요, 얼마나 당황 스럽습니까! 나는 정직하게 내가 참고 문헌을 되 돌리는 것이라고 생각했다. .. 대학에서 더 많은 관심을 기울여야했다 : p –