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...

Explain the need for "Virtual Destructor"?

Answer Posted / p govind rao

A destructor can be declare virtual. virtual destructor is
mainly useful during inheritance.

class base
{
public:
base(){}
virtual ~base(){}
};

class derv
{ char *p;
public :
derv(){ptr=nes char[2];}
~derv(){delete ptr;}

} ;

main()
{
base *baseptr=new derv();
delete baseptr;
}

If base class, and derived class, and a dynamically
allocated object of type derived is deleted via a pointer
of type base, then derived's destructor will not be invoked
unless base's destructor is virtual.

base *baseptr = new derv();
delete baseptr; // won't invoke B's destructor unless A's
destructor is virtual

Is This Answer Correct ?    6 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is c++ proprietary?

1107


What is the difference between an external iterator and an internal iterator? Describe an advantage of an external iterator?

1164


Why c++ is so important?

1139


Give 10 points of differences between C & C++.

1192


Why is that unsafe to deal locate the memory using free( ) if it has been allocated using new?

1121


Write syntax to define friend functions in C++.

1132


Can a program run without main in c++?

1288


What is the best it certification?

1164


How does c++ sort work?

1026


What is the default width for ouputting a long integer using the insertion operator?

1299


What is the equivalent of Pascal's Real a) unsigned int b) float c) char

1061


What is a modifier in c++?

1211


What information can an exception contain?

1206


Can comments be longer than one line?

1127


Describe friend function & its advantages.

1175