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

Explain what are accessor methods?

661


Can we inherit constructor in c++?

582


How we can differentiate between a pre and post increment operators during overloading?

588


When does the c++ compiler create temporary variables?

562


write a c++ program to create class student having datamember name,Roll_no,age,and branch intilcization all the member using constructor print the all the details on the screen.

2244






What is a forward referencing and when should it be used?

573


Is overriding possible in c++?

565


What is the C-style character string?

600


What is c++ programming language?

570


Write a function to find the nth item from the end of a linked list in a single pass.

565


What is a pointer how and when is it used?

571


Write a program to show polymorphism in C++?

621


What is the difference between global variables and static varables?

563


Can we use clrscr in c++?

526


Why c++ is faster than java?

590