Difficulty: Easy
Correct Answer: destructor
Explanation:
Introduction / Context:Resource management in C++ relies heavily on the RAII (Resource Acquisition Is Initialization) idiom. Central to RAII is the special member function that runs automatically when an object's lifetime ends. Knowing its name and role is essential for writing safe, leak-free code that properly closes files, releases memory, and unlocks mutexes.
Given Data / Assumptions:
Concept / Approach:
Step-by-Step Solution:
Identify the life-cycle event: object destruction (end of lifetime).Map the event to the C++ special member function responsible: the destructor.Confirm naming convention: ~ClassName(), no return type, no parameters, optionally virtual.Conclude the correct term is 'destructor' rather than any colloquial synonym.Verification / Alternative check:
Consider std::unique_ptr managing heap memory: when the unique_ptr object is destroyed, its destructor automatically deletes the owned pointer, proving the cleanup role.Why Other Options Are Wrong:
Common Pitfalls:
Final Answer:
destructor
Discussion & Comments