Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

Answers were Sorted based on User's Feedback



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

Answer / guest

If your class has at least one virtual function, you should
make a destructor for this class virtual. This will allow
you to delete a dynamic object through a baller to a base
class object. If the destructor is non-virtual, then wrong
destructor will be invoked during deletion of the dynamic
object.

Is This Answer Correct ?    8 Yes 1 No

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

Answer / 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

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

Answer / som shekhar

If we are deriving from the base class and the base class
consist of some virtual function , then in this case the
base destructor should be virtual.
if you do some thing like this :

base* b = new derived;
delete b;

In this case if base destructor is NOT VIRTUAL then only
base destructor is called and derived destructor wont be
called resulting into memory leak.

But if the base destructor is virtual then derived class
destructor and base destructor both will be called.

Is This Answer Correct ?    1 Yes 0 No

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

Answer / melos

If the class will be derived from and it will need a virtual
destructor so that the destructor of the derived class will
be invoked if it referenced using the pointer to the base class.

Is This Answer Correct ?    1 Yes 1 No

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

Answer / nishikant sahu

If programmer intended to act the class as a BASE class
somewhere then it is rule of thumb or good programming that
you have to have declare your constructor virtual.

Is This Answer Correct ?    3 Yes 6 No

Post New Answer

More C++ General Interview Questions

What is recursion?

6 Answers  


How do you generate a random number in c++?

0 Answers  


What is the difference between operator new and the new operator?

3 Answers   Amazon, TCS, Wipro,


Explain the difference between using macro and inline functions?

0 Answers  


How do you find out if a linked-list has an end? (I.e. The list is not a cycle)

0 Answers  


Explain linear search.

0 Answers  


How do you establish a has-a relationship?

0 Answers  


What are smart pointer? Whats its use?

1 Answers   CTS,


What is the difference between a copy constructor and an overloaded assignment operator?

4 Answers   Belzabar, Citrix, Microsoft, Wipro,


what is the difference between linear list linked representaion and linked representation? what is the purpose of representing the linear list in linked represention ? is it not avoiding rules of linear represention?

0 Answers  


How to declare an array of pointers to integer?

0 Answers  


What is doubly linked list in c++?

0 Answers  


Categories