c++arraysconstructorcontainers

Constructor for a 2d container array of structs


So here is my code and my error is error C2512: 'std::array<std::array<SudokuGrid::Cell,9>,9>' : no appropriate default constructor I thought I was providing that with my public definition but I must be missing something. I have tried to integrate the answer from this question but I can't get the proper method

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);
            }   
    }
};

Solution

  • The default constructor of std::array default constructs the elements it contains. Therefore, SudokuGrid::Cell must have a default constructor:

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

    The full code