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++?
Answer: D. ~Person() — 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…
- A.
Person(string s)
- B.
Person()
- C.
~Person(string s)
- D.
~Person()
Attempted by 492 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.
Loading lesson…