Why and when is a virtual destructor needed?

Answer Posted / guest

Any class that may act as the base of another class should
have a virtual destructor. This ensures that when an object
of the derived class is destroyed that the derived class
dtor will be invoked to destroy it. If the destructor is not
virtual, under some common circumstances, only the base
class' destructor will be invoked, regardless of the class
actually being destroyed. For practical purposes this means
that a class which does, could or should have virtual member
functions, should also have a virtual destructor.

Is This Answer Correct ?    18 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is object-oriented programming? Webopedia definition

715


What is the example of polymorphism?

554


What is the oops and benefits of oops programming?

547


What is multilevel inheritance explain with example?

619


What is oops concept with example?

572






Following are the class specifications: class {int a}; class {int b}; Using friend funtion,calculate the max of two objects and display it.

2000


if i have same function with same number of argument but defined in different files. Now i am adding these two files in a third file and calling this function . which will get called and wht decide the precedence?

2748


Who invented oop?

647


How do you define a class in oop?

620


Why is it so that we can have virtual constructors but we cannot have virtual destructors?

3815


What is polymorphism and example?

588


Why do we use oops?

585


Is abstract thinking intelligence?

588


I have One image (means a group photo ) how to split the faces only from the image?............ please send the answer nagadurgaraju@gmail.com thanks in advace...

1620


What are oops methods?

562