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

What is a constructor in c++ with example?

584


Why cstdlib is used in c++?

586


How is new() different from malloc()?

636


Describe the advantages of operator overloading?

577


write a corrected statement in c++ so that the statement will work properly. x = y = z + 3a;

1461






What is object in c++ example?

630


Keyword mean in declaration?

600


What is a multiset c++?

555


What is data type in c++?

563


What is a constant? Explain with an example.

563


How is computer programming useful in real life?

600


What is the full form of c++?

623


What are separators in c++?

628


What is the array and initializing arrays in c++?

511


Can malloc be used in c++?

574