What is a Desctructor?
As against to a constructor, a destructor is alleged if a program has accomplished
using an instance of an object. A destructor does the charwoman abaft the scenes.
Like the absence constructor, the compiler consistently make a absence destructor
if you don t make one. Like the absence constructor, a destructor aswell has
the aforementioned name as its object. This time, the name of the destructor starts with
To make your own destructor, in the attack file, blazon ~ followed by the name
of the object. Actuality is an example:
TBrick(double L, bifold h, bifold t);
TBrick(const TBrick &Brk);
bifold getLength() const;
abandoned setLength(const bifold l);
bifold getHeight() const;
abandoned setHeight(const bifold h);
bifold getThickness() const;
abandoned setThickness(const bifold t);
As done with a absence constructor, you don t charge to put annihilation in the accomplishing of a destructor. In fact, if a program terminates, the compiler can itself abort all of the altar and variables that your program has used. The alone true time you will be anxious with antibacterial altar is if the altar were created dynamically, which we will apprentice if belief pointers.
You can apparatus your destructor in the attack book by just accouterment it with abandoned parentheses:
Otherwise, you can aswell apparatus it in the cpp book with abandoned parentheses. Actuality is an example:
Discuss this tutorial here
|Forum: Destructors in C++ (Total 0 Messages)|
Also see ...Permalink
Article In : Computers & Technology - C Plus Plus Programming Tutorials