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


Please Help Members By Posting Answers For Below Questions

why is c++ called oops? Explain

666


What is the difference between containment and delegation?

822


Given the following seqment of code containing a group of nested if instructions: y = 9; if ((x==3) || (x == 5)) y++; else if (x == 2) y *= 2; else if (x == ) y-= 7; else y = 8; if the value of x is 4 before the nested IFs are executed, what is the value of y after the nested IFs are executed?

1676


Why should we use null or zero in a program?

685


Is there structure in c++?

679






What is a list c++?

671


What is prototype for that c string function?

772


Is oops and c++ same?

677


What is rtti in c++?

709


Can create new c++ operators?

653


Explain how overloading takes place in c++?

660


How to defines the function in c++?

719


Why was c++ created?

651


What is the use of ::(scope resolution operator)?

738


Explain the static member function.

815