Explain the need for "Virtual Destructor"?
Answer Posted / lylez00
If A is a base class, and from that, B is derived, and a
dynamically allocated object of type B is deleted via a
pointer of type A, then B's destructor will not be invoked
unless A's destructor is virtual.
A *a = new B();
delete a; // won't invoke B's destructor unless A's
destructor is virtual
| Is This Answer Correct ? | 12 Yes | 3 No |
Post New Answer View All Answers
Inline parameters : What does the compiler do with the parameters of inline function, that can be evaluated in runtime ?
Which function cannot be overloaded c++?
What is data hiding c++?
What is code reusability in c++?
What is the difference between structures and unions?
What are containers in c++?
How are pointers type-cast?
What is private, public and protected inheritance?
Describe delete operator?
Can a Structure contain a Pointer to itself?
What are guid? Why does com need guids?
How do you find out if a linked-list has an end? (I.e. The list is not a cycle)
Which bit wise operator is suitable for checking whether a particular bit is on or off?
What is exception handling? Does c++ support exception handling?
What are the advantages of inheritance in c++?