I am new to C ++ and have encountered a problem while doing homework (Sudoku).
Instruction: "you need to create a new board that is a copy of the current board (use the copy constructor and select the board from the heap with a new one).
I tried (this is wriiten in board.cc):
#include "board.h"
Received msg error:
lvalue required as unary '&' operand.
I also tried:
Board* Board::search(void) { Board b; Board *b3; b3 = &b; ... return b3; }
This is not a problem when comp. but it does not work at startup.
How to do it? Actually need help here, thanks!
Here is the code for board.h:
class Board { private: Field fs[9][9]; // All fields on board public: // Initialize board Board(void) { // Uses the default constructor of Field! } // Copy board Board(const Board& b) { for(int i = 0; i < 9; i++){ for(int j = 0; j < 9; j++){ fs[i][j] = b.fs[i][j]; } } } // Assignment operator for board Board& operator=(const Board& b) { if(this != &b){ for(int i = 0; i < 9; i++){ for(int j = 0; j < 9; j++){ fs[i][j] = b.fs[i][j]; } } } return *this; } ....
Full instructions can be found here: http://www.kth.se/polopoly_fs/1.136980!/Menu/general/column-content/attachment/2-2.pdf
Code: http://www.kth.se/polopoly_fs/1.136981!/Menu/general/column-content/attachment/2-2.zip
Ferry source share