+ Reply to Thread
Results 1 to 4 of 4




  

Thread: what is the use of virtual destructor?

      
  1. #1
    I'm New! Rickig is on a distinguished road
    Join Date
    July 9, 2011
    Posts
    11
    Rep Power
    1
    Feedback Score
    0

    Default what is the use of virtual destructor?

    what is the use of virtual destructor?

  2. #2
    I'm New! alize is on a distinguished road
    Join Date
    August 23, 2011
    Posts
    10
    Rep Power
    1
    Feedback Score
    0

    Default Re: what is the use of virtual destructor?

    When object of derived class will be destroyed by invoking the base class destructor then destructor of a class is virtual
    http://www.indianculture.co.in/

  3. #3
    I'm New! Kalin is on a distinguished road
    Join Date
    August 17, 2011
    Posts
    29
    Rep Power
    1
    Feedback Score
    0

    Default Re: what is the use of virtual destructor?

    Virtual destructor is useful at the time when we have a baseclass pointer created with derived class using new. If we try to delete this pointer, it will call the destructor of base class. But, we want the destructor of derived class to be called. So in that case we can make the destructor as virtual. The pseudo code is like this.

    Base* a = new Derived();

    delete a;

    class Base
    {
    .
    .
    .
    ~virtual Base() {
    .
    }
    }
    class Derivedublic Base{
    .
    .
    .
    ~Derived(){
    free a;
    }
    }

  4. #4
    Jedi Master RezwanKabir is on a distinguished road
    Join Date
    July 10, 2011
    Posts
    331
    Rep Power
    1
    Feedback Score
    0

    Default Re: what is the use of virtual destructor?

    A virtual destructor has the keyword virtual in it. If you destroy an object through a caller or reference to a base class, and the base class destructor is not virtual, the derived class destructors are not executed and the destruction is not complete which might lead to memory leaks.
    BLAM Ads makes me over $7,000 a month, read my comment here!
    I switched my traffic from the others and I'm making more!!!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. offering virtual assistant services
    By vrtlassistant in forum Services
    Replies: 2
    Last Post: Aug 29th, 2011, 10:45 pm
  2. Virtual Private Server vs Virtual Dedicated Server
    By Richie_Ni in forum Dedicated / VPS Hosting
    Replies: 29
    Last Post: Feb 6th, 2007, 7:53 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
WebTalkForums
WebTalkForums
Recent Forum Threads