I am trying to generate a two-dimensional array of a struct
, but this results in the program not launching. The window freezes and the program quits after a few seconds. Any idea why?
This is the file where I try to define the array cells
.
#ifndef _FIELD_H_
#define _FIELD_H_
class Field {
public:
static const int minX = -400;
static const int maxX = 400;
static const int minY = 0;
static const int maxY = 400;
Field();
private:
struct absCell {
int material;
float health;
} cells[maxX - minX + 1][maxY - minY + 1];
};
#endif
The program is able to run when I remove these four lines:
struct absCell {
int material;
float health;
} cells[maxX - minX + 1][maxY - minY + 1];
Any idea how this happens? Any help is appreciated!
Update
Okay, apparently the problem is that this array gets quite big. Maybe you can help me to optimize this.
Material has to be an int between 0 and 10. Health has to be a float between 0 and 1 with a maximum of 2 fractional digits.
How can I limit the size of these vars?
Update 2
Mark B suggested the use of vectors
while itwasntpete suggested the use of pointers, new and delete. Where is the difference, what are the advantages and disadvantages of these two methods? Thanks again!