I'm coding a game for my class, and I'm having a segmentation fault when my map array tries to access the symbol of a piece of land to display on a map. I can't figure out how to word this, because I can't figure out where to start when fixing this issue. Any help is appreciated.
Map.h
public:
Map(Player &player) {
...
//Create Map Array Using Size Parameters
Land *map[map_X][map_Y];
this->map = **↦
//Generate Lands on Map
BuildMap(player);
}
...
private:
Land **map;
...
}
};
Map.cpp
void Map::BuildMap(Player &player) {
...
for(size_t i = 0; i < map_Y; i++) {
for(size_t k = 0; k < map_X; k++) {
//!TEST iteration; REMOVE
std::cout << "BuildMap [" << k << "][" << i << "]" << std::endl;
map[k][i] = *GetRandomLand();
//!TEST land; REMOVE
std::cout << "Symbol: \'" << map[k][i].GetSymbol() << "\'" << std::endl
<< std::endl;
//!TEST failsafe; REMOVE
if(k > 100) {
break;
}
}
}
}
Land.cpp
Land* GetRandomLand() {
srand(time(NULL));
LandTypes selection = (LandTypes)(rand() % MAX_LAND_TYPES);
switch(selection) {
case LAKE:
return new Lake;
break;
case FOREST:
return new Forest;
break;
case DESERT:
return new Desert;
break;
default;
return new Forest;
break;
}
}
Edit: I forgot to show it here, but map
is a Land pointer. Specifically,
Land **map
.