Virtual Destructor

Total Post:113

Points:791
C#  Java 
 254  View(s)
Ratings:
Rate this:
What is virtual Destructor?
  1. Post:140

    Points:984
    Re: Virtual Constructor

    Virtual Destructor :

    Destructor means destroy the class.The virtual attributes declared the virtual destructor. A base class reference destroy by an object through a pointer but base class destructor is not virtual.the derived-class destructors are not executed, and the destruction might not be complete. 

    Ex: 

    struct X{ 
      virtual ~Y() {}
      virtual X * Clone() { return new X; }
    };
    struct Y : public X {
      virtual X * Clone() { return new Y; }
    }; int main() {
       X * x1 = new Y;
       X * x2 = x1->Clone(); // virtual construction
       delete x2;
       delete x1;
    }

      Modified On Jun-20-2018 05:56:00 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!