Constructors and Destructors

Constructors and destructors are special member functions of a class that are automatically called when an object is created or destroyed, respectively.

For example:

class MyClass {
public:
  MyClass() { // constructor
    // initialization code
  }

  ~MyClass() { // destructor
    // cleanup code
  }
};