Examveda

What is the purpose of a virtual destructor in C++?

A. To prevent memory leaks when deleting objects of derived classes through base class pointers.

B. To prevent memory leaks when deleting objects of base classes.

C. To ensure proper destruction of derived class objects when deleted through a base class pointer.

D. To ensure proper memory alignment for polymorphic objects.

Answer: Option C


Join The Discussion

Related Questions on Polymorphism in C plus plus

What is polymorphism in C++?

A. A feature that allows objects of different classes to have the same name.

B. A feature that allows functions to perform different tasks based on the object they are called with.

C. A feature that allows the same function to have different implementations.

D. A feature that allows inheritance of multiple classes.