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

What is extern c++?

752


What is the C-style character string?

845


What is unary operator? List out the different operators involved in the unary operator.

805


Explain the static storage classes in c++.

958


What is a constructor in c++ with example?

838


What are the advantages of using a pointer?

843


Why is c++ still popular?

812


How does a copy constructor differs from an overloaded assignment operator?

807


Is it possible to pass an object of the same class in place of object reference to the copy constructor?

813


How are the features of c++ different from c?

811


What is the best c++ ide?

857


When is the copy constructor called?

904


Which of the following is evaluated first: a) && b) || c) !

2090


What are the two main components of c++?

842


What do you mean by early binding?

816