二维容器结构数组的构造函数
Constructor for a 2d container array of structs
这是我的代码,我的错误是 error C2512: 'std::array<std::array<SudokuGrid::Cell,9>,9>' : no appropriate default constructor
我以为我在 public 定义中提供了它,但我一定遗漏了一些东西。我试图整合 this 问题的答案,但我无法获得正确的方法
class SudokuGrid
{
private:
struct Cell{
int value;
bitset<9> pencils;
bool isSolved;
Cell(int i, bitset<9> p, bool s):
value{ i = 0 },
pencils{ p.reset() },
isSolved{ s = false }{}
};
array < array < Cell, 9>, 9 > _grid;
public:
SudokuGrid(string s) :_grid{}
{
for (int i = 0; i < 9; i++)
for (int j = 0; j < 9; j++)
{
bitset<9> p;
p.reset();
_grid[i][j] = Cell(0, p, false);
}
}
};
std::array
default constructs 它包含的元素的默认构造函数。因此,SudokuGrid::Cell
必须有一个默认构造函数:
Cell():
value(0),
pencils(),
isSolved(false){}
完整代码位于:http://goo.gl/CdpCH6
这是我的代码,我的错误是 error C2512: 'std::array<std::array<SudokuGrid::Cell,9>,9>' : no appropriate default constructor
我以为我在 public 定义中提供了它,但我一定遗漏了一些东西。我试图整合 this 问题的答案,但我无法获得正确的方法
class SudokuGrid
{
private:
struct Cell{
int value;
bitset<9> pencils;
bool isSolved;
Cell(int i, bitset<9> p, bool s):
value{ i = 0 },
pencils{ p.reset() },
isSolved{ s = false }{}
};
array < array < Cell, 9>, 9 > _grid;
public:
SudokuGrid(string s) :_grid{}
{
for (int i = 0; i < 9; i++)
for (int j = 0; j < 9; j++)
{
bitset<9> p;
p.reset();
_grid[i][j] = Cell(0, p, false);
}
}
};
std::array
default constructs 它包含的元素的默认构造函数。因此,SudokuGrid::Cell
必须有一个默认构造函数:
Cell():
value(0),
pencils(),
isSolved(false){}
完整代码位于:http://goo.gl/CdpCH6