when can we use virtual destructor?

Answer Posted / sagarson

Need for a virtual destructor
1.destructor for the base parts are invoked automatically
2.we might delete a ptr to the base type that actually
points to a derived object
3.if we delete a ptr to base then the base class destructor
is run and the members of the base class are cleared up. If
the object is a derived type then the behavior is undefined
4.to ensure that the proper destructor is run the destructor
must be virtual in the base class
5.virtual destructor needed if base pointer that points to a
derived object is ever deleted (even if it doesnt do any work)

Is This Answer Correct ?    34 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a list c++?

564


How can you quickly find the number of elements stored in a static array? Why is it difficult to store linked list in an array?

573


Can a built-in function be recursive?

572


Explain selection sorting?

628


Can a program run without main function?

608






Can we declare a base-class destructor as virtual?

577


Explain the use of this pointer?

622


How do you establish an is-a relationship?

612


What is difference between rand () and srand ()?

581


What is prototype for that c string function?

678


What is the meaning of c++?

531


What are friend functions in C++?

610


How does a C++ structure differ from a C++ class?

610


How to declare a pointer to an array of integers?

633


What ANSI C++ function clears the screen a) clrscr() b) clear() c) Its not defined by the ANSI C++ standard

577