I am having trouble with this. I am using a int array with 4 elements that stores a position and where to move. Think of it as x1, y1 moves to x2,y2. I want to use a array to store this info (int a[4] = {x1,y1,x2,y2}). I want to add this array to a list so I want to use "list<int[4]> moves;". I dont know the number of moves that will be generated so I dont want to use a 2D array and I might be moving the arrays in the list around later on (some moves might have a higher priority).
So I want to use:
list<int[4]> moves;
and add stuff like:
int a[4] = {1,2,3,4};
moves.push_back(a);
but "push_back" does not work, compile error.
I was thinking of just using a struct to hold the array:
typedef struct _move { int a[4]; } move;
and just using "list<move> moves;". I like the struct way since i can add on more like what game piece does the move refer to with an "int type" (if I can get the list of arrays working this would have been another element making it a[5] instead of a[4] ) but I would like to know why I cant do an list of arrays?
Question
Doli
I am having trouble with this. I am using a int array with 4 elements that stores a position and where to move. Think of it as x1, y1 moves to x2,y2. I want to use a array to store this info (int a[4] = {x1,y1,x2,y2}). I want to add this array to a list so I want to use "list<int[4]> moves;". I dont know the number of moves that will be generated so I dont want to use a 2D array and I might be moving the arrays in the list around later on (some moves might have a higher priority).
So I want to use:
list<int[4]> moves;
and add stuff like:
int a[4] = {1,2,3,4};
moves.push_back(a);
but "push_back" does not work, compile error.
I was thinking of just using a struct to hold the array:
typedef struct _move { int a[4]; } move;
and just using "list<move> moves;". I like the struct way since i can add on more like what game piece does the move refer to with an "int type" (if I can get the list of arrays working this would have been another element making it a[5] instead of a[4] ) but I would like to know why I cant do an list of arrays?
Link to comment
Share on other sites
2 answers to this question
Recommended Posts