I have class Walls in my program. Inside of class are objects Wall1, Wall2 etc. I want to do something like this: class definition:
class Walls {
public:
Walls(){
nPositionX = nMapWidth - 1;
nHoleSize = 1;
nHolePosition = rand()%(nMapHeight - nHoleSize);
count++;
}
static int getCount() {
return count;
}
int getPositionX()
{
return nPositionX;
}
private:
int nPositionX;
int nHolePosition;
int nHoleSize;
static int count;
};
access to object
for (int i = 0; i < Walls::getCount(); i++) {
int nPosx = Wall"i".getPositionX();
}
}
Is that possible in c++? Ok big thanks for everyone for help. I don't know why I didn't tried it before.
std::vectorto maintain a collection.std::mapusing name strings as keys, ie:std::map<std::string, Wall> walls; ... int nPosx = walls["Wall" + std::to_string(i)].getPositionX();Walls.