C++ destructors: how many arguments does a destructor take?

Difficulty: Easy

Correct Answer: no

Explanation:


Introduction / Context:
Destructors release resources and perform cleanup when an object’s lifetime ends. Understanding their signature is essential for writing correct RAII classes (Resource Acquisition Is Initialization) in C++. This question asks about the parameter list for a destructor.


Given Data / Assumptions:

  • A destructor is written as ~ClassName() in C++.
  • We focus on its parameter rules and overloading possibilities.
  • We consider standard C++ without extensions.


Concept / Approach:

By definition, a destructor cannot take parameters and cannot return a value. Its spelling includes an empty parameter list. You also cannot overload a destructor; each class has exactly one destructor (which may be implicitly generated, defaulted, deleted, or user-defined). Therefore, the correct completion is that a destructor takes “no” arguments.


Step-by-Step Solution:

Recall the form: ~ClassName(). Notice the empty parentheses: there are no parameters. Confirm language rule: no overloading and no parameters allowed. Therefore, select “no.”


Verification / Alternative check:

Attempting to declare ~ClassName(int); fails to compile. Only special cases like virtual destructors change dispatch, not the parameter list.


Why Other Options Are Wrong:

one/two/three — contradict the C++ grammar for destructors.


Common Pitfalls:

  • Confusing destructor parameters with constructor parameters; only constructors may take arguments.
  • Trying to overload a destructor to specialize cleanup paths (use strategy objects instead).


Final Answer:

no

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion