1

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

GaussianMex::~GaussianMex()
{
   int i;
}
David Rodríguez - dribeas
  • 198,982
  • 21
  • 284
  • 478
Fadwa
  • 1,457
  • 2
  • 22
  • 38

4 Answers4

17

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
  • 499
  • 3
  • 13
5

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
  • 37,292
  • 10
  • 72
  • 122
2

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
  • 58,802
  • 11
  • 90
  • 132
1

You are defining the destructor of the class GaussianMex.

Ivaylo Strandjev
  • 66,530
  • 15
  • 117
  • 170