4

In the following piece of code, what is the meaning of ::~

GaussianMex::~GaussianMex()
{
   int i;
}
David Rodríguez - dribeas
  • 204,818
  • 23
  • 294
  • 489
Fadwa
  • 1,717
  • 5
  • 26
  • 43

4 Answers4

19

This is not a single operator ::~, but a definition of GaussianMex destructor. You define class methods by ClassName::ClassMethod syntax and since destructor name is ~ClassName resulting destructor definition is ClassName::~ClassName.

Alex Watson
  • 519
  • 3
  • 13
7

This is a destructor.

Consider:

class GaussianMex
{
public:

    // This is the CONstructor (ctor).  It is called when an instance of the class is created
    GaussianMex()
    {
    };

    // This is a Copy constructor (cctor).  It is used when copying an object.
    GaussianMex(const GaussianMex& rhs)
    {
    };


    // This is a move constructor.  It used when moving an object!
    GaussianMex(GaussianMex&& rhs)
    {
    };


    // This is the DEStructor.  It is called when an instance is destroyed.
    ~GaussianMex()
    {
    };


    // This is an assignment operator.  It is called when "this" instance is assigned
    // to another instance.
    GaussianMex& operator = (const GaussianMex& rhs)
    {
        return *this;
    };


    // This is used to swap two instances of GaussianMex with one another.
    friend void swap(GaussianMex& lhs, GaussianMex& rhs)
    {
    };
};  // eo class GuassianMex

The purpose of a constructor is to do any initialisation that is required (perhaps allocating memory, or other class instances). The destructor does the opposite - it performs the clean up of any resources the class allocated during its' lifetime.

Moo-Juice
  • 38,257
  • 10
  • 78
  • 128
3

It indicates that the method is a destructor.

Your class can have at most one destructor, and it is always the name of the class prefixed with the ~ symbol.

The destructor is called whenever an instance of your object is destroyed. This happens whenever an instance goes out of scope, or when you call delete on a pointer to an instance the the class.

Sean
  • 60,939
  • 11
  • 97
  • 136
2

You are defining the destructor of the class GaussianMex.

Ivaylo Strandjev
  • 69,226
  • 18
  • 123
  • 176