C++ destructors: passing arguments to a destructor is considered which kind of error? Identify the compile-time classification.

Difficulty: Easy

Correct Answer: syntax

Explanation:


Introduction / Context:
Destructors have a fixed signature in C++. They cannot accept parameters. This question asks how the language treats an attempt to pass arguments to a destructor.



Given Data / Assumptions:

  • Destructor form: ~ClassName().
  • No parameters permitted and no overloading by parameter list.
  • Call sites use implicit destruction at scope end or delete.



Concept / Approach:
If you write ~T(42) or declare ~T(int), the code violates the language grammar. Such violations are detected by the compiler's parser and type checker, resulting in a compile-time syntax error (ill-formed program). It is not a runtime or linking concern.



Step-by-Step Solution:
1) Valid declaration: struct T { ~T(); }.2) Invalid declaration: ~T(int); → compile-time syntax error.3) Invalid explicit call with arguments: obj.~T(1); → compile-time error.4) Therefore, the correct classification is syntax error.



Verification / Alternative check:
Test in any conforming compiler; the front end rejects parameterized destructor declarations or calls.



Why Other Options Are Wrong:
Logical/virtual/linker/runtime: none describe a violation of the language grammar found at compile time.



Common Pitfalls:
Trying to pass context into a destructor. If cleanup requires data, store it as members beforehand; destructors must remain parameterless.



Final Answer:
syntax


Discussion & Comments

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