Question discussion

Why is declaring a base class destructor as virtual considered best practice in C++ when a class is intended to be used polymorphically?

560Medium DSSSB TGT Computer Science 0 replies 1 views
0
Why is declaring a base class destructor as virtual considered best practice in C++ when a class is intended to be used polymorphically?
  • AIt improves compilation speed
  • BIt ensures the derived class's destructor is also called when deleting a derived object through a base pointer, preventing resource leaks
  • CIt is required by the C++ standard for all classes
  • DIt automatically makes all member functions virtual
Correct answer: B

Discussion 0

Nobody has replied yet. Start the discussion!