gpt4 book ai didi

c++ - 二维容器结构数组的构造函数

转载 作者:行者123 更新时间:2023-11-30 03:54:12 25 4
gpt4 key购买 nike

这是我的代码,我的错误是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

关于c++ - 二维容器结构数组的构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29728232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com