I have tried creating a vector of vectors in a class with a fixed size using the solution from the following thread but to no avail. Initializing a vector of vectors having a fixed size with boost assign
Since it's 7 years old, I'm thinking it could be something to do with C++17 changes, but I'm unsure where the issue is otherwise. The error the IDE tells me is "expected a type specifier" on the first argument. Having a look at the documentation for constructors, nothing seems wrong, unless I missed something.
class SudokuSolver {
public:
SudokuSolver() {}
~SudokuSolver() {}
private:
std::vector<std::vector<int>> sudoku_field(9, std::vector<int>(9, 0));
};
You can use squiggly brackets to let the compiler know you're trying to call a constructor:
std::vector<std::vector<int>> sudoku_field{9, std::vector<int>(9, 0)};
Alternatively, you could do this work in the initialization list of your default constructor:
SudokuSolver() : sudoku_field(9, std::vector<int>(9, 0)) {}
And then run your default constructor from every new constructor you make to ensure that gets set:
SudokuSolver(int thing) : SudokuSolver() { }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.