【发布时间】:2016-09-06 07:46:37
【问题描述】:
此代码是一个更大项目的一部分。我试图了解如何通过使用引用将 2d 向量传递给另一个函数。这是我当前的代码,我无法弄清楚错误是什么(使用 Xcode)。
代码:
int main()
{
int mines, col, row;
int test;
cout << "\nHow many many rows of boxes?" <<endl; //getting row,
//column and mines from user
cin >> row;
cout << "\nHow many many columns of boxes?" <<endl;
cin >> col;
cout << "\nHow many many mines are in the board?" <<endl;
cin >> mines;
test=(row*col)-1; // test to make sure that the whole gameboard is not filled with mines (multiplies row and columns and subtracts by 1)
while (!(test>= mines)) // if there are more mines than cells or if the whole board is filled with mines, will ask for mines again
{
cout << "\nHow many many mines are in the board?" <<endl;
cin >> mines;
}
vector <vector<int> > grid(col, vector<int>(row)); //create 2d vector with col and row as parameters
minesweeper(row, col, mines, vector< vector<int> > grid(col, vector<int>(row))) //sends all data to minesweeper();
return 0;
}
void minesweeper(int row,
int col,
int numOfMines,
vector<vector<int>>& mineField)
{
}
编辑:
对不起,我完全搞砸了这个问题。那是深夜,我忘了复制标题和声明。
【问题讨论】:
标签: c++ xcode vector 2d pass-by-reference