Initializations of user-defined types

I´m trying to declare an array of 100 sudokus, but how can I do so without calling my default constructor?

 
sudoku game(3,0);

is the propper way of declaring a single 9x9 empty sudoku.

I'm trying to get the following code to work:
 
sudoku gamez[100](3,0);

which gives me the error message: bad array initializer.

Instead of:
1
2
3
4
5
6
7
sudoku gamez[100];

for (int i = 0; i < 100; ++i)
    {
        gamez[i].resize(3);
        gamez[i].cleargrid();
    }


which uses the default constructor which prompts the user for the size of the sudoku. I don't want to remove this functionality from the default constructor, however I don't want to have to enter the size for each of the sudokus in the array either. How can I do this?
Use a vector and its default value constructor.

http://www.cplusplus.com/reference/stl/vector/vector/

Your class will need a working assignment operator and copy constructor for this to work.

std::vector<sudoku> gamez(100, sudoku(3,0));
Last edited on
Topic archived. No new replies allowed.