【发布时间】:2014-02-05 03:20:09
【问题描述】:
我正在尝试制作井字游戏,并且我想将井字棋盘位置的二维数组传递给绘制更新棋盘的函数。我希望我的函数“updateBoard”的参数值能够从 main 中获取板的内存地址,这样我就可以在整个程序中使用它而不必担心范围。编译时出现错误:
错误 C2664: 'updateBoard' : 无法将参数 1 从 'char (*)[3][3]' 转换为 'char *[][3]' 1> 指向的类型不相关;转换需要 reinterpret_cast、C-style cast 或 function-style cast
这是我的代码:
#include "stdafx.h"
#include <iostream>
using namespace std;
void updateBoard (char *n[3][3])
{
}
int getMove ()
{
int input;
cout <<"\n";
cout <<"1 for square 1| 2 for square 2| and so on... : ";
cin >>input;
return 0;
}
int main ()
{
const int WIDTH = 3;
const int HEIGHT = 3;
char board [WIDTH][HEIGHT] = {' ', ' ', ' ',
' ', ' ', ' ',
' ', ' ', ' '};
updateBoard(&board);
char f;
cin >>f;
}
【问题讨论】: