Destructors in C++
| |
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 Interface' onMouseOver="tip('infobox1')" onMouseOut="untip()" target='_parent'> compiler Interface' onMouseOver="tip('infobox2')" onMouseOut="untip()" target='_parent'> compiler Interface' onMouseOver="tip('infobox1')" onMouseOut="untip()" target='_parent'> compiler Interface' onMouseOver="tip('infobox2')" onMouseOut="untip()" target='_parent'> 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
a tilde.
To make your own destructor, in the attack file, blazon ~ followed by the name
of the object. Actuality is an example:
#ifndef BricksH
#define BricksH
class TBrick
{
public:
TBrick();
TBrick(double L, bifold h, bifold t);
TBrick(const TBrick &Brk);
~TBrick();
bifold getLength() const;
abandoned setLength(const bifold l);
bifold getHeight() const;
abandoned setHeight(const bifold h);
bifold getThickness() const;
abandoned setThickness(const bifold t);
bifold CementVolume();
abandoned ShowProperties();
private:
bifold Length;
bifold Height;
bifold Thickness;
};
#endif
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 Interface' onMouseOver="tip('infobox1')" onMouseOut="untip()" target='_parent'> compiler Interface' onMouseOver="tip('infobox2')" onMouseOut="untip()" target='_parent'> compiler Interface' onMouseOver="tip('infobox1')" onMouseOut="untip()" target='_parent'> compiler Interface' onMouseOver="tip('infobox2')" onMouseOut="untip()" target='_parent'> 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:
#ifndef BricksH
#define BricksH
class TBrick
{
public:
...
~TBrick() {}
...
private:
...
};
#endif
Otherwise, you can aswell apparatus it in the cpp book with abandoned parentheses. Actuality is an example:
TBrick::~TBrick()
{
}
Discuss this tutorial here
Forum: Destructors in C++ (Total 0 Messages) | |||
Also see ...
C++ Anamnesis Administration
C++ Anamnesis Management/H2PBy George Belotsky/A /PPPublished on Linux DevCenter (http://www.linuxdevcenter.com//A)BRhttp://www.linuxdevcenter.com/pub/a/linux/2003/05/08/cpp_mm 1.html/PPEveryone knows that anamnesis administration is a difficul
Addendum on Programming in C++
Introduction/h2Kernighan and Plaugers IThe Elements of Programming Appearance /Iwas an important and accurately affecting book. But sometimes I feel its abridged rules were taken as a cookbook access to acceptable appearance instead of the blunt announceme
|
Forum: Destructors in C++ (Total 0 Messages)