【发布时间】:2020-06-25 02:15:49
【问题描述】:
我收到 EXC BAD ACCESS 错误。不确定是什么问题。我正在尝试测试二维向量内的单元格。我希望它打印一个 0 的 20x20 的网格
struct Cell {
int test;
Cell(): test(0) {}
};
class Board {
public:
Board() {
for (int i = 0; i < 20; i++) {
Cell temp;
cellVec[i].resize(20, temp);
}
}
friend ostream& operator<<(ostream& out, const Board& boardPrint) {
for (int i = 0; i < 20; i++) {
for (int j = 0; j < 20; j++) {
out << boardPrint.cellVec[i][j].test;
}
}
return out;
}
private:
vector< vector<Cell> > cellVec;
};
int main() {
Board newBoard;
cout << newBoard;
}
【问题讨论】:
标签: c++ oop multidimensional-array vector