我試圖把我的地圖渲染(控制檯,ASCII)到一個函數,但它不編譯。 它應該是這個樣子:C++通過引用傳遞位域數組
struct tiles {
unsigned is_visible : 1;
//...
} tile[y][x];
void render_map(const tiles (tile&)[y][x]) {
for (int i = 0; i < y; i++) {
if (tile[y].is_visible == 0) {
//...
}
}
}
int main() {
render_map(tile);
//...
}
我嘗試做在這樣的回答:C++ pass an array by reference。 (瓦片&)[y] [x])
感謝所有,現在它的工作!
struct tiles {
unsigned is_visible : 1;
//...
} tile[y][x];
void render_map(const tiles (&tile)[y][x]) {
for (int i = 0; i < y; i++) {
for (int j = 0; j < x; j++) {
if (tile[i][j].is_visible == 0) {
//...
}
}
}
}
int main() {
render_map(tile);
//...
}
我會考慮使用矢量。 對不起,這種愚蠢的問題:)
你得到了什麼錯誤? – DOOM 2014-10-04 16:55:57
使用矢量並像這樣傳遞'const vector>&' –
2014-10-04 16:57:22