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 are multiple inheritances (virtual inheritance)? What are its advantages and disadvantages?

772


what is COPY CONSTRUCTOR and what is it used for?

787


Will c++ be replaced?

804


What is the real purpose of class – to export data?

814


find the two largest values among the 6 numbers using control structures : do-while,for,if else,nestedif- else ,while. one or two of them.

2186






You run a shell on unix system. How would you tell which shell are you running?

868


What is the function to call to turn an ascii string into a long?

797


What does ctime() do?

778


By using c++ with an example describe linked list?

783


What is a c++ map?

911


What is the difference between an external iterator and an internal iterator? Describe an advantage of the external iterator.

767


What is a local reference?

887


Describe Trees using C++ with an example.

817


State two differences between C and C++.

785


Why was c++ made?

824