Professional Documents
Culture Documents
Submitted to
Submitted by
: Group members
Date
: 27-04-16
Topic
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. Designate a function as a class's destructor by preceding the class name with a tilde (~).
Syntax:
The syntax of declaring destructor is as follows:
~name()
{
Destructor body
}
~name()
It indicates the name of the destructor. The name must be same as the name of the
class in which the constructor is declared.
Rules of destructor:
Program:
The working of below program is, The add() function in below program accepts a parameter
object of type Marks. It adds the contents of parameter and calling object and stores the result in
a temporary object. The function then returns the whole object back to main() function that is
stored in r. The program finally displays the result using r.show() statement.
Following program containing Destructor, Object as function parameters and returning object
from member functions.