I am trying to call a function on an object, but I'm getting this error. I have two classes: a Sudoku class and a Puzzle class. The Sudoku class inherits the Puzzle class. The Sudoku class has protected variable, a 2D array of Puzzle objects Puzzle libraryOfPuzzles[4][10];
When I try to call the setSolution function on a the libraryOfPuzzles[][];
, it doesn't work. However, when I call it on a Puzzle test[4][10];
that is created inside the function itself, it works. Why is this?
void Sudoku::createLibraries(string name) {
Puzzle test[4][10]; //added for demonstration purposes
string fileName = "";
int i = 0;
for (int k = 0; k < 40; k++) {
fileName = name + to_string(k) + ".txt";
string aWord;
ifstream fin;
fin.open(fileName);
i = 0;
int value = 0;
while (!fin.eof()) {
fin >> aWord;
int value = stringToInt(aWord);
libraryOfPuzzles[k / 10][k % 10].setSolution(i / 9, i % 9, value); //this line gives error
test[k / 10][k % 10].setSolution(i / 9, i % 9, value); //this line is fine
i++;
}
fin.close();
}
}