-4

I am facing this type of function:

class Menu: public Activity
{
private:

   // something defined here

public:
   Menu();
   ~Menu();

   // something defined here
}

I am learning C++ and can not understand of how "~Menu()" function works? When will we need this function? Is this something relevant to overload function? Can anyone explain me? Thank you.

Cory Kramer
  • 114,268
  • 16
  • 167
  • 218
NTinside
  • 3
  • 1

1 Answers1

1

That function is the destructor. It takes care of any cleanup you would like to do when the object is going out of scope.

Menu();   // Constructor
~Menu();  // Destructor

Depending on how trivial the class is, you may even need to define a constructor and destructor, as the compiler will generate them for you. There are, of course, plenty of examples of cases where you need to do some specific work, so you can define them if you'd like.

Cory Kramer
  • 114,268
  • 16
  • 167
  • 218