For my C++ class assignment, I have to implement a copy constructor for a forward list. However, there are instructions in the assignment that confuse me. Specifically, the part saying that I must create a new node for each value in the forward list. I am unsure of what it wants me to do exactly. If I create nodes that store the values, wouldn't that be the same as making a linked list?
I have no idea what a copy constructor would look like for a forward list, so can someone give me some pointers to where I can learn how?
// Copy constructor
// ***For you to implement
// The copy constructor takes as argument a const reference to a
// another Forward_list "other"
// The const means that the function should not modify other
// The function should make a "deep copy" of the other list,
// that is create a new node for every node in other and copy
// the data of other into these new nodes.
template <typename T>
Forward_list<T>::Forward_list(const Forward_list& other)
{
}
Yes. The purpose of a copy constructor of a linked list is to make a copy of the linked list that is being passed into the constructor.
You aren't creating nodes for the other list. You are creating nodes for the list that you are constructing.
Yes. A copy constructor should create a copy.