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 an iterator class in c++?

590


Is c++ a good beginners programming language?

578


Can member data be public?

591


Explain the concept of friend function in c++?

597


What does new in c++ do?

560






What is private public protected in c++?

545


Which software is best for c++ programming?

570


List different attributes in C++?

639


Define anonymous class.

621


Is nan a c++?

606


Write a program using display() function which takes two arguments.

601


Why cout is used in c++?

557


What are static and dynamic type checking?

604


Mention the storage classes in c++.

636


Is java a c++?

554