Why should a base class used polymorphically have a virtual destructor?
-
A
So derived classes skip the base destructor
-
B
So the object is reclaimed by a collector
-
C
So deleting through a base pointer is complete
Correct answer
-
D
So the destructor may be called twice
Correct answer
C. So deleting through a base pointer is complete
14 views
Explanation
Without a virtual destructor, deleting via a base pointer is undefined behaviour and skips the derived destructor.
Reference
Asked in: NTS, PPSC IT, Campus Interviews
Doubts & discussion
Not sure why the answer is C? Ask here and get an explanation.
Ask a doubt about this MCQ