Internal arrays are apparently tied to size 2. You can use a vector to do this. array
static std::vector< array<int, 2> > getFreeCellList(int grid[][9]) {
int numberOfFreeCells = 0;
for (int i=0; i<9; i++)
for (int j=0; j<9; j++)
if (grid[i][j] == 0)
numberOfFreeCells++;
std::vector< array<int, 2> > freeCellList(numberOfFreeCells);
int count = 0;
for (int i=0; i<9; i++)
for (int j=0; j<9; j++)
if (grid[i][j] == 0) {
freeCellList[count][0] = i;
freeCellList[count++][1] = j;
}
return freeCellList;
}
Usage is similar to
int x[9][9] = { ... };
std::vector< array<int, 2> > pa = getFreeCellList(x);
, std::vector. array boost,
template<typename E, int N>
struct array {
E &operator[](int I) { return data[I]; }
E data[N];
};
N E.
, 2d-. , , 2d- 1d- :
static identity<int[2]>::type *getFreeCellList(int grid[][9]) {
int numberOfFreeCells = 0;
for (int i=0; i<9; i++)
for (int j=0; j<9; j++)
if (grid[i][j] == 0)
numberOfFreeCells++;
int (*freeCellList)[2] = new int[numberOfFreeCells][2];
int count = 0;
for (int i=0; i<9; i++)
for (int j=0; j<9; j++)
if (grid[i][j] == 0) {
freeCellList[count][0] = i;
freeCellList[count++][1] = j;
}
return freeCellList;
}
int x[9][9] = { ... };
// equivalent: identity<int[2]>::type *pa = ...;
int (*pa)[2] = getFreeCellList(x);
// ...
delete[] pa;
identity ( boost . ), .
static int (*getFreeCellList(int grid[][9]))[2] {
}
template<typename T>
struct identity { typedef T type; };