I have written the following code for operator overloading for my class called board.
Note that there is no return statement.
board& board:: operator=(const board& rhs)
{
for(int i =0; i< 5; i++)
for(int j=0; j < 5;j++ )
{
squares[i][j].value = rhs.squares[i][j].value;
squares[i][j].piece = rhs.squares[i][j].piece;
}
asterScore = rhs.asterScore;
dollarScore = rhs.dollarScore;
}
Also I have used it in the main() as follows
board1 = *tempBoard; //where tempBoard is board* and board1 is board type.
The code works (to my surprise!) . I wonder why the compiler did not give me a return statement error. And could someone please advice on the proper way of using the operator overloading function? (above code modified?).
Thanks in advance.

New Topic/Question
Reply




MultiQuote




|