CoolInterview.com - World's Largest Collection of Interview Questions
Home| Ask Questions| About Us| Feedback| Contact Us|
 Interview Questions  
 Our Services  

Get 9,000 Interview Questions & Answers in an eBook.


  • 9500+ Pages
  • 9000 Question & Answers
  • All Tech. Categories
  • 14 MB Content

    Get it now !!



    Send your Resume to 6000 Companies

  • COOLINTERVIEW.COM LANGUAGES C++ DETAILS



    Question :
    What Is The Use of VirtualDestructer?
    Contact Author  Contact Author


    Answer :
    Virtual destructor is used for the polymorphic decomposition of allocated resources.

     Posted by: Vishal Singh    

    Contact Author  Contact Author
    in the case of multiple inheritance same member function in both and derived class exist then the two copies of childs will be created. so there is an ambiguity between which function to execute so virtual functions are introduced.we can accept the derived and based class methods with help of pointers.if pointer points to base method then base method will be executed.if it points to derive then derive will be executed so in order to delete these pointers we go for virtual desstructors

     Posted by: krishna    

    Contact Author  Contact Author
    virtual destructer is used so that while deleting the pointer to base class but pointing to base class invokes the derived class destructor first,then the base class destruct hence preventing memory leak...

     Posted by: praveen    

    Contact Author  Contact Author
    First pls get clear with virtual function conceptss...
    suppose we have a class hierachy
    Empl-->Manager-->CEO
    now we are creating
    Empl* e1;
    CEO c1;
    e1= & c1;
    Now when ever my e1 goes out of scope because e1 is of type Empl only the destructor of e1 is called & memory is freed for attributes of e1 only. ? for Manager & CEO attributes so we have the memory leakage problem

    so if we are making Destructor as a virtual so exceutin of destructor will follow
    ~CEO-->~Manager-->~Empl path so Memory for all the data is freed.....

    so to avoid these Memory Leakage problem we have to make destructor as a virtual destructor.....

    Now if u have understood the explanation pls tell me
    Can we have virtual constructor???




     Posted by: Mihir P Trivedi    

    Contact Author  Contact Author
    virtual destructors are used to deallocate the memory in prper order if the memory is allocated through new
    for example
    base *p;
    p=new derive;
    firstly the base class constructor would be called followd by the derive class
    if we now say delete p then destruction should proceed from derive to base.
    this can be ensured by declaring base class destructor virual

     Posted by: Rohit Adhlakha    

    Contact Author  Contact Author

    © CoolInterview.com
    Today's Special: Get Free Magazine from SAP now!

    A D V E R T I S E M E N T








    If you have the better answer, then send it to us. We will display your answer after the approval.
    Name :*
    Email Id :*
    Answer :*
    Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
    Process Verification  Enter the above shown code:*
    Inform me about updated answers to this question

       


    Rate the above answer. Help us to know about the answer.
    Category C++ Interview Questions
    Rating (4.3) By 3 users
    Added 9/12/2007
    Views 6184
    Rate it!
    Free Offers 300 Free Magazines for you. No credit card required. No Shipping Charges. Absolutely Free for 1 Year.

    Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

    Notify me when better answer is posted!
    Email:

    View ALL C++ Interview Questions


    Sponsored Links  

    Google Search

    Google

    CoolInterview.com is a part of Vyom Network.
    Copyright ©2003-2009 Vyom Technosoft Pvt. Ltd., All Rights Reserved. Privacy Policy
    Page URL: http://www.coolinterview.com/interview/11333/Default.asp?cachecommand=bypass


    Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial

    0.98