【发布时间】:2011-03-09 11:25:28
【问题描述】:
想法是 MapGrid 创建并保存带有地图元素的二维数组,我想将该数组提供给另一个类 MapGenerator,以便它通过编辑其中的方形元素来生成真实地图。
class MapGenerator {
private:
int MAP_HEIGHT;
int MAP_WIDTH;
Square * worldMap;
void cmdGenerateHeightMap() {
worldMap[i][j]->decraseHeight();
......
}
public:
MapGenerator(Square &myMap, int maxHeight, maxWidth) {
MAP_WIDTH = maxWidth
MAP_HEIGHT = maxHeight;
worldMap = &myMap;
cmdGenerateHeightMap();
}
}
class MapGrid {
private:
static const int MAP_HEIGHT = 100;
static const int MAP_WIDTH = 100;
Square worldMap[MAP_HEIGHT][MAP_WIDTH];
public:
MapGrid() {
for (int i=0; i<MAP_HEIGHT;i++) {
for (int j=0;j<MAP_WIDTH; j++) {
worldMap[i][j] = Square();
}
}
MapGenerator myMap(worldMap);
}
void PrintMyMap() {
//print what the map MapGenerator made
}
}
我收到此错误:变量“MapGenerator myMap”具有初始化程序但类型不完整 map.h 我可以得到一些更人性化的提示什么是错的
【问题讨论】:
-
“MapGenerator myMap(worldMap);”在 MapGrid 方法中的作用是什么?
标签: c++ arrays class reference