CS 70

Phase 6

In this phase, you will implement the following constructor from the IntList class:

  • The copy constructor

and as a result, the assignment operator will also work:

  • operator=(…) (the assignment operator, already written using the copy-and-swap idiom)

Remember to keep the

open for reference!

Steps

1. Plan

  • Plan how the copy constructor should work.
  • Add an image, Phase_6.jpg, to the intlist/Planning folder in your assignment repository.
  • Make sure the file was added successfully by viewing it on the GitHub website.

2. Write Tests

  • Write tests for the copy constructor and add them to intlist-test.cpp.

3. Implement

  • Use your plan to implement the copy constructor in intlist.cpp.

4. Test & Fix

  • See if you can find any bugs in your implementation, and if you do, sort them out.
  • Think about how someone else might have accidentally fundamentally misunderstood how to copy the list and make sure your test would catch those kinds of mistakes.

Helpful Hints

Reuse Your Code!

You can use your iterator and your push_back() function to get the job done.

  • LHS Cow speaking

    You can even use C++'s iterator-for-loop that we learned about in Lesson 2 from Week 7 and just have it use your iterator entirely automatically.

  • Goat speaking

    Heh, less code. I'll bite.

To Complete This Part of the Assignment…

You'll know you're done with this part of the assignment when you've done all of the following:

(When logged in, completion status appears here.)