Destructors in C++

puzzlegamesios wordgamesios appcolt
 31 December 18:00   

    

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

    

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 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)

 


Tags: create, program, object

 double, destructor, const, tbrick, default, constructor, ~tbrick, objects, program, create, object, destructors, , const double, const void, default constructor, define brickshclass tbrick{public, bricksh define brickshclass, ifndef bricksh define,

Share Destructors in C++: Digg it!† †Google Bookmarks†† Del.icio.us†† Yahoo! MyWeb†† FurlBinklist†† Reddit!   Stumble Upon   Technorati   Windows Live   Bookmark

Text link code :
Hyper link code:

Also see ...

Permalink
Article In : Computers & Technology  -  C Plus Plus Programming Tutorials