How do you know that your class needs a virtual destructor?

Answer Posted / abc

When We Declare a Virtual Function In Base Class.
The Base Class Pointer Can Point To Derived Class objects.
And If we Try To Delete The Base Class Pointer ,it will Call
the base Class Destructor(Which Is Wrong).

To Handle Such Scenario,The Base Class Destructor need To
Be Declared As Virtual(Which Makes All The Derived Class
Destructors Virtual).Now The Base Class Pointer Will Call
The Respective Destructors(Ofcourse,It Is Decided at Run
Time.With The Virtual Mechanism.)

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why do we need pointers?

665


Is map ordered c++?

688


What c++ library is string in?

692


What are the four partitions in which c++ compiler divides the ram?

849


Is c++ an integer?

673






What are the advantages of using friend classes?

723


what is scupper?

1979


What is extern c++?

610


Does there exist any other function which can be used to convert an integer or a float to a string?

731


How we can differentiate between a pre and post increment operators during overloading?

675


What is the oldest programming language?

667


Which format specifier is used for printing a pointer value?

668


What is abstraction c++?

677


Mention the storage classes in c++.

740


Write a Program for find and replace a character in a string.

663