In which of the following scenarios should a destructor be declared virtual in a base class?
A. When the destructor of the base class will be doing the clean-up of the derived class data
B. When an implementation for the derived class destructor is not desired
C. When a derived class allocates system resources which are released in its destructor
D. When the developer wants to ensure that a derived class destructor is invoked when an instance is destroyed through a base class pointer
E. When the default constructor of the base class is declared as virtual
Ok, I feel:
* A is correct, because destructor are not inherited. And IIRC to call the base class destructor from the derived class, the base class must be virtual.
* B is incorrect, because we only use virtual if we want the derived class to over right the base class destructor.
* C is correct, because we want the derived class destructor to more the derived classes memory.
* D is incorrect, because the derived class destructor is not invoked when the base class is destroyed.
* E is incorrect, as the constructor is separate from the destructor.
Can someone please confirm. Thx.