Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual Basic6 Database Programming

Authors: John W. Fronckowiak, David J. Helda

1st Edition

ISBN: 0764532545, 978-0764532542

More Books

Students also viewed these Databases questions

Question

Shift of HR policy-making from local to central level.

Answered: 1 week ago