Member function that overloads the assignment operator
Overloading Assignment Operator =
Write a member function that overloads the assignment operator for the matrix class so that the operator assigns one two-dimensional array to another.
Before looking at overloading the assignment operator, you may want to review the use of
Look at the binary operator overloading by focusing on the safe array class from the Building Classes in C++
course. It would be convenient to assign one array to another. We can specify the behavior of assignment by overloading the assignment operator (=).
It is good style to maintain consistency with standard usage and avoid creating personal algebras.
We can add the following member function, which overloads the assignment operator for the vect class:
Move your mouse cursor over the 1) operator= 2) assert and 3) for loop to to read a description of their purpose.
Now with the class vect, the following expressions are meaningful:
a = b; //a, b are type vect
a = b= c; //a, b, c are type vect
a = vect(data, DSIZE); //convert array data[DSIZE]
Overloading Assignment Exercise
Click the Exercise link below to write a member function that overloads the assignment operator for the matrix class so that the operator assigns one two-dimensional array to another. Overloading Assignment Exercise