Which of the following functions should be the destructor function for user…
2022
Which of the following functions should be the destructor function for user defined class Person in C++?
- A.
Person(string s)
- B.
Person()
- C.
~Person(string s)
- D.
~Person()
Attempted by 153 students.
Show answer & explanation
Correct answer: D
In C++, a destructor must be named with the class name preceded by a tilde symbol and cannot accept parameters. Option 3 correctly defines ~Person() which strictly adheres to this specific syntax requirement for user-defined classes.