Question: The following code defines the overloading assignment operator = for bag class with a linked list. What will happen if we do a self-assignment with

The following code defines the overloading assignment operator = for bag class with a linked list. What will happen if we do a self-assignment with this code, e.g., b = b (b is an object of class bag)? If the result is inaccurate, find if anything is missed.

void bag::operator =(const bag& source)

{

node *tail_ptr; // Needed for argument to list_copy

list_clear(head_ptr);

many_nodes = 0;

list_copy(source.head_ptr, head_ptr, tail_ptr); many_nodes = source.many_nodes;

}

Here, many_nodes is a private member in the bag class to record the number of nodes in the list. You can also find both precondition and postcondition of list_clear and list_copy in our textbook (page 256).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!