【发布时间】:2013-02-21 05:28:35
【问题描述】:
我有一个相对简单的问题,但我似乎找不到特定于我的案例的答案,而且我可能没有以正确的方式解决这个问题。我有一个看起来像这样的类:
struct tileProperties
{
int x;
int y;
};
class LoadMap
{
private:
ALLEGRO_BITMAP *mapToLoad[10][10];
tileProperties *individualMapTile[100];
public:
//Get the struct of tile properties
tileProperties *getMapTiles();
};
对于 getter 函数,我有一个如下所示的实现:
tileProperties *LoadMap::getMapTiles()
{
return individualMapTile[0];
}
我在 LoadMap 类中有代码,它将为数组中的每个结构分配 100 个图块属性。我希望能够在我的 main.cpp 文件中访问这个结构数组,但我似乎无法找到正确的语法或方法。我的 main.cpp 看起来像这样。
struct TestStruct
{
int x;
int y;
};
int main()
{
LoadMap _loadMap;
TestStruct *_testStruct[100];
//This assignment will not work, is there
//a better way?
_testStruct = _loadMap.getMapTiles();
return 0;
}
我意识到有很多方法可以解决这个问题,但我试图让这个实现尽可能私密。如果有人能指出我正确的方向,我将不胜感激。谢谢!
【问题讨论】: