C++ 将2D数组设置为函数,并根据需要在其他位置调用它

C++ 将2D数组设置为函数,并根据需要在其他位置调用它,c++,C++,所以我有这个变量,我想把它作为函数传递给下面的代码,这些代码仍然不起作用,但是有什么想法吗??我也很高兴知道我们是否可以添加ctime来跟踪用户的到达,谢谢您的帮助 bool spt_1 [15][12] = {0} 这是我想要传递的代码,这样我可以稍后在代码中的某个地方调用它 int col = 1; int row = 1; for (col = 1 ; row < 16 ; row ++) { if (spot_1 [col][row] == 0) { cout<

所以我有这个变量,我想把它作为函数传递给下面的代码,这些代码仍然不起作用,但是有什么想法吗??我也很高兴知道我们是否可以添加ctime来跟踪用户的到达,谢谢您的帮助

bool spt_1 [15][12] = {0} 
这是我想要传递的代码,这样我可以稍后在代码中的某个地方调用它

int col = 1;
int row = 1;

for (col = 1 ; row < 16 ; row ++) {

  if (spot_1 [col][row] == 0) {

cout<<"There is a place reserved for you in spot, the first column , row number "<<" "<<row<<"."<<endl;

string choice;

do {

cout<<"\nDo you want to take that spot? Y/N.\n"<<endl;
cin>>choice;
cout<<"\n"<<endl;

transform(choice.begin(), choice.end(), choice.begin(), toupper); 
}while (choice != "Y" && choice !="YE" && choice != "YES" && cout<<"Wrong input!\n"<<endl);

cout<<"\nHave a nice day.\n"<<endl;
break;

 if (choice == "YES") {

spot_1 [col][row] = 1; // should change that specific 0 to 1 ( which means occupied )

 }

else  {

//it should reject count ++;

} 
 if (spot_1 [col][row] != 0) { // When there is no more place it should cout this and go search in a new array and do same as first one

cout<<"Sorry ,There is no more place available , But you can go to :\n"<<endl;   
    } 
   }
  }
}
int col=1;
int行=1;
用于(列=1;行<16;行++){
如果(点1[col][row]==0){

cout首先,您可能应该使用2D向量而不是该数组。但是,如果确实需要使用数组,您可以定义如下模板函数:

template <int Row, int Col>
void some_func(bool my_array[Row][Col])
{
    //do your stuff
    //here just printing the array and changing a value
    for (int i = 0; i < Row; i++)
    {
        for (int j = 0; j < Col; j++)
            std::cout << my_array[i][j];
        std::cout << std::endl;
    }
    my_array[3][4] = false;
}
some_func<15,12>(spt_1);
模板
作废一些函数(bool my_数组[行][列])
{
//做你的事
//这里只是打印数组并更改一个值
对于(int i=0;i谢谢你的帮助,我的朋友,但我对向量不熟悉。标准的空函数能做到吗?
void some_func(void* my_pointer, int row, int col)
{
    bool* my_pointer_arr = static_cast<bool*>(my_pointer);
    for (int i = 0; i < row * col; i += col)
    {
        for (int j = 0; j < col; j++)
            std::cout << my_pointer_arr[i + j];
        std::cout << std::endl;
    }
    my_pointer_arr[3 * col + 4] = false;
}