[英]'…' is not a type c++ compilation error
I am writing a small game for an assignment and it requires using a map, I have successfully put the map into a 2d array, but now working further into the assignment I found I need to access the array Map[][] in another function. 我正在为任务编写一个小型游戏,它需要使用地图,我已经成功地将地图放入了2d数组中,但是现在进一步研究该任务,我发现我需要在另一个函数中访问数组Map [] [] 。 I have tried to get it to work but failed. 我试图使其正常运行,但失败了。 The error I get with g++ is " error: 'Map' is not a type " Any help would be appreciated. 我用g ++遇到的错误是“错误:'Map'不是类型'任何帮助将不胜感激。
I have searched but either I am terrible at using the search engine or I couldn't find anything specific to this error. 我已经搜索过,但是要么使用搜索引擎很糟糕,要么找不到与此错误有关的任何信息。
const int MapSZ = 10; //In Global
int Map[MapSZ][MapSZ]; // Also Global
void GetMap(ifstream&, int); //Getting the map (Proto)
GetMap(fin, Map[MapSZ][MapSZ]); //In the main function.
void GetMap(ifstream& fin, Map[MapSZ][MapSZ]) //Inserting the map into an array
void GetMap(ifstream& fin, Map[MapSZ][MapSZ])
should be: 应该:
void GetMap(ifstream& fin, int Map[MapSZ][MapSZ])
^^^^
Notice, that Map
is the name of the array, but you didn't mention its type . 注意, Map
是数组的名称 ,但是您没有提到它的type 。
If Map[MapSZ][MapSZ]
is defined as a global, as your comment states (ie it is defined in main.cpp
but outside of the main function), there is no need to pass it as a parameter to GetMap
. 如果将Map[MapSZ][MapSZ]
定义为全局对象,则正如您的注释所指出的(即,它在main.cpp
但在main函数外部定义),则无需将其作为参数传递给GetMap
。 You could simply do something like 你可以简单地做
void GetMap(ifstream& fin); //proto
int main(int argc, const char * argv[]) {
GetMap(fin);
}
void GetMap(ifstream& fin) {
//some code that uses Map[MapSZ][MapSZ]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.