C++ terminology check: in this class, what is the technical term for ~CuriousTab() ?
#include
class CuriousTab{
int x, y;
public:
CuriousTab(int xx=10,int yy=20){ x=xx; y=yy; }
void Display(){ cout << x << " " << y << endl; }
~CuriousTab(){ }
};
int main(){ CuriousTab obj; obj.Display(); }
-
AConstructor
-
BDestructor
-
CDefault Destructor
-
DFunction Template
Answer
Correct Answer: Destructor
Explanation
Introduction / Context:C++ uses a special member function prefixed with a tilde (~) as the object's destructor. It runs automatically when an object's lifetime ends and is used to release resources.
Given Data / Assumptions:
- The class defines
~CuriousTab(). - No other special semantics are implied.
Concept / Approach:By definition, any member named ~ClassName with no return type and no parameters is the class destructor.
Step-by-Step Solution:1) Identify the tilde-prefixed member.2) Recognize destructor signature (no return type, no parameters).3) Conclude that it is the destructor.
Verification / Alternative check:Add logging inside ~CuriousTab() to observe it runs at scope exit or upon delete.
Why Other Options Are Wrong:Constructor is CuriousTab(...), not ~CuriousTab(). “Default Destructor” is not standard terminology; here it is a user-defined destructor. It is not a function template.
Common Pitfalls:Confusing compiler-generated defaulted destructor with a user-defined one; both are destructors nonetheless.
Final Answer:Destructor