Question: 41. What is the term for the function in a C++ class definition that can de-allocate dynamic memory when the object goes out of scope,

41.What is the term for the function in a C++ class definition that can de-allocate dynamic memory when the object goes out of scope, as in a return from a function which has created a local object?

Group of answer choices

Tilde function

Exit

Deconstructor

Destructor

42. Why do we need to overload the assignment operator in some class interfaces, such as in String& String::operator=(const String& other)?

Group of answer choices

To copy buffers used by both the object on the left and the object on the right side of the equals

To delete (free) unused memory pointed to by the object

All of these

To prevent memory leaks

43. Which line(s) of code will complete this function from the textbook example String class?

String& String::operator=(const String& other) { if (this != &other) { delete[] buffer; len = other.len; if (len > 0) { buffer = new char[len]; for (int i = 0; i < len; i++) { buffer[i] = other.buffer[i]; } } else { buffer = nullptr; } } _____________________________//line(s) of code go(es) here }

Group of answer choices

return buffer;

return *this;

delete[] buffer;

All of these

44. Which of the following is the proper function prototype for the String class copy-constructor?

Group of answer choices

String::String(const String& other)

String::String()

String::String(String this, const String& other)

String::String=(const String& other)

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!