Friday, 15 March 2013

c++ - How to return an array of structs from a class in a getter function -



c++ - How to return an array of structs from a class in a getter function -

i have relatively simple question cant seem find reply specific case , may not approaching problem right way. have class looks this:

struct tileproperties { int x; int y; }; class loadmap { private: allegro_bitmap *maptoload[10][10]; tileproperties *individualmaptile[100]; public: //get struct of tile properties tileproperties *getmaptiles(); };

i have implementation looks getter function:

tileproperties *loadmap::getmaptiles() { homecoming individualmaptile[0]; }

i have code in loadmap class assign 100 tile properties each struct in array. want able access array of structs in main.cpp file cant seem find right syntax or approach. main.cpp looks this.

struct teststruct { int x; int y; }; int main() { loadmap _loadmap; teststruct *_teststruct[100]; //this assignment not work, there //a improve way? _teststruct = _loadmap.getmaptiles(); homecoming 0; }

i realize there many approaches this, i'm trying maintain implementation private possible. if please point me in right direction appreciate it. give thanks you!

teststruct *_teststruct; _teststruct = _loadmap.getmaptiles();

this pointer first element in array returned. can iterate through other 99.

i highly recommend using vectors, or container, , writing getters don't homecoming pointers bare arrays that.

c++ arrays struct allegro

No comments:

Post a Comment