Defining operator=()

Given the following stub-definition for the assignment operation:

   List& List::operator=(const List& rhs) { // rhs == right hand side
   }
one way to implement the operation is using the following steps:
  1. If rhs and I are two distinct lists (Note: use & and this, as we've done previously):
    1. Deallocate my chain of nodes.
    2. Set myFirst and myLast to nullptr.
    3. Set mySize to zero.
    4. Declare nPtr containing the address of rhs's first node.
    5. While nPtr is pointing at something:
      1. Append (to me) a copy of the item in the node to which nPtr is pointing.
      2. Advance nPtr to the next node.
  2. Return myself.
Note that the logic in steps 1.b, 1.c, 1.d, and 1.e is identical to the logic of the copy constructor. The other steps (1, 1.a, and 2) reflect the differences between the assignment operation and the copy constructor operation.

Rather than copy-and-paste the copy constructor's logic into your assignment operator (propagating any logic errors it might contain), consider highlighting the body of the copy constructor and then using Eclipse's Refactor > Extract function mechanism to extract the body of the copy constructor into a method named makeCopyOf(). Eclipse will create a new method containing the code you've highlighted, and then replace the highlighted code with a call to that new method. You can then invoke that new method in your assignment operator (passing it rhs as an argument) to perform steps 1.b, 1.c, 1.d, and 1.e, greatly simplifying your assignment operation.