Question: (C++) Please overload the assignment operator for the UnsortedType class, and then provide a copy constructor for the UnsortedType class. UnsortedType(int init_size=MAX_ITEMS); //constructor ...... overloading

(C++) Please overload the assignment operator for the UnsortedType class, and then provide a copy constructor for the UnsortedType class.

UnsortedType(int init_size=MAX_ITEMS); //constructor

......

overloading the assignment operator...

UnsortedType & UnsortedType::operator=(const UnsortedType & right) //assignment operator overload { if (this!=&right) //if this is not the same object as right { if (info!=NULL) //it's our responsibility to set info appropriately delete [] info; //Todo by you: perform deep copy // } return *this; }

In the deep copy..

for the assignment operator, deallocate the dynamic array of this object first allocate the space for the dynamic array of this object copy array elements from the given UnsortedType object to the current object. 

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!