OOPortal
J2EEOnline RationalDB
prev next prev next
  Course navigation
 
Lesson 10
Objective
Overloading the assignment operator
Member function that overloads the 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 reference declaration.
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.
New Assignment
We can add the following member function, which overloads the assignment operator for the vect class:
Program dissection
Move your mouse cursor over the highlighted lines of code below for a pop-up discussion of their purpose.
Operator Program Dissection
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 button 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
  Course navigation