Practice mode C++

According to the Rule of Three, a class that needs a user-defined destructor usually also needs which two special members?

Correct answer D. A copy constructor and a copy assignment operator

Explanation

A user-defined destructor usually means the class manages a resource, such as raw memory or a file handle. The compiler-generated copy constructor and copy assignment would copy only the handle, leading to double frees or leaks, so those two need custom definitions too. In C++11 the Rule of Five extends this to the move constructor and move assignment operator.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.