void erase(){
int row = rand()%9; int col = rand()%9;
int r, c;
m_map[row][col].erase(m_map[row][col].begin() + row);
}
however there is an error with the erase
So you're trying to call the erase() method of a cell object. Does cell have an erase() method?
I'm guessing that what you really want to do is call erase() on one of the vectors, rather than on a cell.
The above is also true of m_map[row][col].begin() on the same line.
By the way, telling us "there is an error" is not very helpful. Your compiler is giving you helpful information about what that error is. Why would you withhold that information from us? The more help you give us, the more help we can give you.
If this is a straightforward Soduko grid then erase() is surely not deleting a cell but simply clearing its contents and resetting to some default value.
OP: You are using the term 'erase' erroneously as it means something entirely different in vector-speak. In STL 'erase' removes either a single element or a range of elements from the vector. So if you were to call erase on your board you'd just be left with gaping hole(s). What you need really is to reach inside any cell of the board and manipulate it's m_num data members with the setter you've already defined, setMark() (whose parameter should be passed by reference incidentally):
Now you define a cell_change method in class board:
1 2 3 4 5 6
void board::cell_change(const size_t& i, const size_t& j, constint& n)
//scroll down I notice later board::setMark() is doing this why does it have to return bool?;
{
m_map[i][j].setMark(num);
}
Couple of other points:
- in class cell, method getNum()const should be const qualified;
- the insertion operator overload needs to be re-worked a bit and defined outside the class since it's a friend function:
1 2 3 4 5 6 7 8 9 10 11 12 13
friend ostream& operator << (ostream& o, const cell& c)
{
if (c.m_occu)
{
o << setw(2) << c.m_num;//additional newline and/or tab may be required here to attain desired visual effect;
}
else
{
o << setw(2) << '-';
}
return o;
}
I was thinking, how would it be possible for me to set a random cell to the value of 0, and then show that if cell = 0 then show "-", this was my attempt
1 2 3 4 5
void erase(){
srand(time(0));
int row = rand()%9; int col = rand()%9;
m_map[row][col].getNum() = 0;
}
however, at m_map[row][col]... I get a compiler error that says that: "lvalue required as left operand of assignment."
This logic was inspired by the above comment, I am thinking if 0is a default value, I can set a random cell to 0 within the vector and the vector will show as "-".
I guess my question should be that in this case with respect to user-defined types, how could I change the value of a cell of type cell in a vector<vector<cell> >.
Thanks for the help, I got it to work and now its working without error.
All that is left is the verify() function. How can I check for the correctness of the board as per the rules of Sudoku, especially in a 3 by 3 box like below?
A B C D E F G H I
P 3 4 5 9 1 - 7 6 8
Q 6 7 8 3 4 5 1 9 2
R 9 1 2 6 7 8 4 3 5
S 2 3 4 8 9 1 6 5 7
T 5 6 7 2 3 4 9 8 1
U 8 9 1 5 6 7 3 2 4
V 1 2 3 7 8 9 5 4 6
W 4 5 6 1 2 3 8 7 9
X - 8 9 4 5 6 2 1 3
> verify
- Found inconsistency in row P...
- Found inconsistency in row X...
- Found inconsistency in column A...
- Found inconsistency in column F...
- Found inconsistency in component starting at row P and column D...
- Found inconsistency in component starting at row V and column A...
> quit
Bye...