It turns out I had somethings in the wrong order, and not in the right scope. After successfully doing it with a while loop, I found the solution with a for loop.
bool DoTheWork::addSquare(int& depth, ostream& outStream){
for(int i = 1; i < 10; ++i){
for(int j = 1; j < 10; ++j){
if(board.getSquare(i, j) == 0){
if(i == 10){
return true;
}
for(int k = 1; k <= 9; ++k){
board.setSquare(i, j, k);
if(board.isLegal() && addSquare(depth, outStream)){
return true;
}
}
board.unsetSquare(i, j);
return false;
}
}
}
}