1
所以這裏是我的代碼和我的錯誤是error C2512: 'std::array<std::array<SudokuGrid::Cell,9>,9>' : no appropriate default constructor
我以爲我提供了與我的公共定義,但我必須缺少的東西。我試圖回答的問題this整合,但我不能得到正確的方法構造函數的2d容器數組的結構
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);
}
}
};
表達'*新Cell(O,P,假);'創建*內存泄漏*,則分配內存並取消引用返回的指針,然後丟棄指針。相反,例如'_grid [i] [j] =單元格(...);'。 –
另外,在發佈有關構建錯誤的問題時,請在問題中包含完整和未編輯的構建日誌,並在代碼中標出錯誤的位置。請修改您的問題以包含該信息。 –
但是,考慮一下'std :: array'非常像普通數組,因此數組中的對象將在創建數組時創建,因此您需要一個* default *構造函數。如果你不做任何特殊的陣列構造。 –