wij
2024-07-14 09:21:19 UTC
Why g++ reports "error: invalid types ‘unsigned int[int]’ for array subscript"?
--------------------------
void t() {
int z[3][3][3] = {
{{1,2,3}, {4,5,6}, {7,8,9}},
{{11,12,13}, {14,15,16}, {17,18,19}},
{{21,22,23}, {24,25,16}, {27,28,29}},
};
cout << z[1][2][0]; // OK
for(unsigned int x=0; x<3; ++x) {
for(unsigned int y=0; y<3; ++y) {
for(unsigned int z=0; z<3; ++z) {
// cout << z[x][y][z];
cout << z[1][2][0]; // g++ error: invalid types ‘unsigned int[int]’ for array subscript
}
}
}
}
--------------------------
void t() {
int z[3][3][3] = {
{{1,2,3}, {4,5,6}, {7,8,9}},
{{11,12,13}, {14,15,16}, {17,18,19}},
{{21,22,23}, {24,25,16}, {27,28,29}},
};
cout << z[1][2][0]; // OK
for(unsigned int x=0; x<3; ++x) {
for(unsigned int y=0; y<3; ++y) {
for(unsigned int z=0; z<3; ++z) {
// cout << z[x][y][z];
cout << z[1][2][0]; // g++ error: invalid types ‘unsigned int[int]’ for array subscript
}
}
}
}