我有一个相对简单的问题,但我似乎找不到适合我的案例的答案,我可能不会以正确的方式处理这个问题。我有一个类,看起来像这样:如何在一个getter函数中返回一个类的结构数组
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;
}
我意识到有很多方法来做到这一点,但我试图尽可能保持这种实现。如果有人能指点我正确的方向,我将不胜感激。谢谢!
可能重复的[从函数返回数组](http://stackoverflow.com/questions/6422993/return-an-array-from-function) – jogojapan 2013-02-21 05:33:13