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
If
Map[MapSZ][MapSZ]is defined as a global, as your comment states (i.e. it is defined inmain.cppbut outside of the main function), there is no need to pass it as a parameter toGetMap. You could simply do something like