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
What are multiple inheritances (virtual inheritance)? What are its advantages and disadvantages?
what is COPY CONSTRUCTOR and what is it used for?
Will c++ be replaced?
What is the real purpose of class – to export data?
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.
You run a shell on unix system. How would you tell which shell are you running?
What is the function to call to turn an ascii string into a long?
What does ctime() do?
By using c++ with an example describe linked list?
What is a c++ map?
What is the difference between an external iterator and an internal iterator? Describe an advantage of the external iterator.
What is a local reference?
Describe Trees using C++ with an example.
State two differences between C and C++.
Why was c++ made?