Virtual Destructor

Total Post:113

C#  Java 
 314  View(s)
Rate this:
What is virtual Destructor?
  1. Post:140

    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. 


    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