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
Refer to a name of class or function that is defined within a namespace?
Which operations are permitted on pointers?
Which ide is best for c++?
When should we use multiple inheritance?
Is c# written in c++?
Explain what are single and multiple inheritances in c++?
What are the advantages of inheritance in c++?
What would happen on forgetting [], while deallocating an array through new?
How a pointer differs from a reference?
What are c++ templates used for?
How can a called function determine the number of arguments that have been passed to it?
Are vectors passed by reference c++?
What is stream and its types in c++?
explain the reference variable in c++?
What is vector string in c++?