结构的二维容器数组的构造函数

Constructor for a 2d container array of structs

本文关键字:构造函数 二维 数组 结构      更新时间:2023-10-16

这是我的代码,我的错误是error C2512: 'std::array<std::array<SudokuGrid::Cell,9>,9>' : no appropriate default constructor我以为我提供了我的公共定义,但我一定错过了一些东西。我试图整合这个问题的答案,但我无法获得正确的方法

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的默认构造函数构造它包含的元素。因此,SudokuGrid::Cell必须具有默认构造函数:

Cell():
    value(0),
    pencils(),
    isSolved(false){}

完整代码可在以下网址获得: http://goo.gl/CdpCH6