BY
T.DEEPIKA M.SC(INFO TECH)
NADAR SARASWATHI COLLEGE OF ARTS
ANDSCIENCE
What is destructor?
 A destructor is a special member function that is
called when the lifetime of an object ends.
 The purpose of the destructor is to free the resources
that the object may have acquired during its lifetime.
DEFINITION OF DESTRUCTOR:
A Destructor is used to destroy the objects
that have been created by constructor.
Like a constructor the destructor is a
member function whose name is the same
as the class name but is preceded by a
tilde.
FOR EXAMPLE:
The destructor for the class integer can be
Tell in or defined in
~integer(){}
• We define the destructor by the symbol
“TILDE”(~).
A Destructor never takes any arguments
nor does it return any value
Destructor are mainly used for in future
use for memory space.
• Implicitly by the complier exit from the
program to clean up storage that is for no
longer accessible.
• In constructor allocate the memory by
using “new” and “delete” used to delete
memory.
PROGRAM LOGIC:
Matrix::~matrix()
{
For(int i=0;i<d1;i++)
Delete p(i);
Delete p;
}
A Destructor is not called implicitly.
Destructor mainly used for destroy the
object.
Destructor in c++:
 A destructor is called for a class object when that
object passes out of scope or is explicitly deleted
 It is mainly used for deallocate memory and clean up
the class object and its class members.
C++
 A destructor is a special method called automatically
during the destruction of an object.
 Actions executed in the destructor include the following:
 Recovering the heap space allocated during the lifetime of
an object.
 Closing file or database connections.
 Releasing network resources.
Overload destructor
 Destructor is mainly used to delete the object
and so only one time to call destructor when the
overloading is not occur
 Destructor it needs to call when you destroy an
object
Destructors

Destructors

  • 1.
    BY T.DEEPIKA M.SC(INFO TECH) NADARSARASWATHI COLLEGE OF ARTS ANDSCIENCE
  • 2.
    What is destructor? A destructor is a special member function that is called when the lifetime of an object ends.  The purpose of the destructor is to free the resources that the object may have acquired during its lifetime.
  • 3.
    DEFINITION OF DESTRUCTOR: ADestructor is used to destroy the objects that have been created by constructor. Like a constructor the destructor is a member function whose name is the same as the class name but is preceded by a tilde.
  • 4.
    FOR EXAMPLE: The destructorfor the class integer can be Tell in or defined in ~integer(){} • We define the destructor by the symbol “TILDE”(~).
  • 5.
    A Destructor nevertakes any arguments nor does it return any value Destructor are mainly used for in future use for memory space.
  • 6.
    • Implicitly bythe complier exit from the program to clean up storage that is for no longer accessible. • In constructor allocate the memory by using “new” and “delete” used to delete memory.
  • 7.
  • 8.
    A Destructor isnot called implicitly. Destructor mainly used for destroy the object.
  • 9.
    Destructor in c++: A destructor is called for a class object when that object passes out of scope or is explicitly deleted  It is mainly used for deallocate memory and clean up the class object and its class members.
  • 10.
    C++  A destructoris a special method called automatically during the destruction of an object.  Actions executed in the destructor include the following:  Recovering the heap space allocated during the lifetime of an object.  Closing file or database connections.  Releasing network resources.
  • 11.
    Overload destructor  Destructoris mainly used to delete the object and so only one time to call destructor when the overloading is not occur  Destructor it needs to call when you destroy an object