Constructors and Destructors

Constructors initialize objects when they're created. Destructors clean up when objects go out of scope.

class Car {
  public:
    Car() {
      cout << "Constructor called\n";
    }
    ~Car() {
      cout << "Destructor called\n";
    }
};

Constructors can be overloaded and can accept parameters too.

← PrevNext →