This is homework
I\'m working on implementing a linked list class for my C++ class, and the copy constructor has be very confusing for me.
T
You shouldn't set this->head = v.head
. Because the head is simply a pointer. What you need to do is to create a new head and copy the values individually from v.head
into your new head. Otherwise you'd have two pointers pointing to the same thing.
You then would have to create a temporary Elem
pointer that starts with v.head
and iterate through the list, copying its values to new Elem
pointers into the new copy.
See above.