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?

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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is difference between c++ and c ++ 14?

1035


Write a short code using c++ to print out all odd number from 1 to 100 using a for loop

1009


Is it possible to use a new for the reallocation of pointers ?

1043


What are the 3 levels of programming languages?

1031


Explain storage qualifiers in c++.

1070


What is a block in c++?

1039


Write a program for Divide a number with 2 and Print the output ( NOTE: Check for divide by zero error).

1100


Can I have a reference as a data member of a class? If yes, then how do I initialise it?

1212


What is c++ best used for?

1053


What is the function of I/O library in C++ ?

1177


Who was the creator of c++?

1034


What do you know about near, far and huge pointer?

1121


What is the use of endl in c++ give an example?

1151


What happens when the extern "c" char func (char*,waste) executes?

1070


What is a v-table?

1157