(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
Destructer
1. Destructer
NAME:- PRAJAPATI JAY R
ENROLLMENT NO:- 170950107074
CLASS/DIVISION:- CSE-B
SEMESTER:- 4TH
GUIDED BY:- ASTT.PROF.DHRUTI PANDYA
2. WHAT IS
DESTRUCTER?
• Destructor is a member function which destructs or deletes an object.
• Destructors are usually used to deallocate memory and do other cleanup
for a class object and its class members when the object is destroyed.
• A destructor is called for a class object when that object passes out of
scope or is explicitly deleted.
3. When is destructor
called?
• A destructor function is called automatically when the object goes out of
scope:
(1) the function ends
(2) the program ends
(3) a block containing local variables ends
(4) a delete operator is called
4. How destructors
are different from
a normal member
function?
• Destructors have same name as the class preceded by a tilde (~)
• Destructors don’t take any argument and don’t return anything
• If no user-defined destructor exists for a class and one is needed, the
compiler implicitly declares a destructor. This implicitly declared destructor
is an inline public member of its class.
• The compiler will implicitly define an implicitly declared destructor when
the compiler uses the destructor to destroy an object of the destructor's
class type. Suppose a class A has an implicitly declared destructor.
5. Rules:-
1) Name should begin with tilde sign(~) and must match
class name.
2) There cannot be more than one destructor in a class.
3) Unlike constructors that can have parameters,
destructors do not allow any parameter.
4) They do not have any return type, just like
constructors.
5) When you do not specify any destructor in a class,
compiler generates a default destructor and inserts it into
your code.