cpp_programming/Destructor at master · Lavin-tom/cpp_programming · GitHub
Skip to content

Latest commit

 

History

History

Destructor

A destructor is a special method that is called automatically when an object goes out of scope. Destructors are used to free any resources that the object is using, such as memory or other resources.

example :

class Example {
public:
    Example() {
        // Some constructor code here
    }
    ~Example() {
        // Free any resources used by the object here
    }
};

When the Example object goes out of scope, its destructor will be called automatically, which in this case would free any resources used by the object.

Destructors are a powerful feature of C++ that can help you to ensure that our objects are properly cleaned up after they are no longer needed.


Next