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. 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.
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 .
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
. 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]
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.