【发布时间】:2013-12-04 16:51:01
【问题描述】:
编辑:可能找到了解决方案
我想将二维数组设置为二维返回,但它总是给我一些无意义的错误:
In function 'int main()':
error: expected primary-expression before ']' token
error: expected primary-expression before ']' token
In function 'int initBoard(int (*)[25])':
error: invalid conversion from 'int (*)[25]' to 'int' [-fpermissive]
我无法弄清楚哪里出了问题以及如何消除错误。
#include <iostream>
using namespace std;
const short WIDTH = 80;
const short HEIGHT = 25;
int clearBoard();
int initBoard(int board[WIDTH][HEIGHT]);
int drawBoard();
int main()
{
int board[WIDTH][HEIGHT] = {{0}};
board = initBoard(board); // problem is this place AND should be initBoard(board);
cout << board[79][24]
return 0;
}
int initBoard(int board[WIDTH][HEIGHT])
{
unsigned int localWidth = 1;
unsigned int localHeight = 1;
while(localHeight < HEIGHT)
{
while(localWidth < WIDTH)
{
board[localWidth][localHeight] = 0;
localWidth++;
}
localHeight++;
localWidth = 1;
}
}
【问题讨论】:
-
欢迎来到 Stack Overflow。请尽快阅读About 页面。您确定您粘贴的代码会生成关于
]的两个错误吗?它不应该;当我编译代码时它不会。 (它合理地抱怨其他事情,但它并没有抱怨。)您可能必须在程序上运行预处理器并查看输出,这可能令人生畏(我从前 17 行得到了 16437 行输出代码行;幸运的是,我只需要查看最后 17 行输出)。如果你使用g++,试试g++ -E program.cpp,看看数组定义是否OK。
标签: c++ arrays multidimensional-array