我试图把我的地图渲染(控制台,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