22. Destruction of objects

The problem is that free is just an ordinary function that must be called explicitly.

C++ classes can define a special cleanup function - destructor

Destructor functions are the opposite of constructors.

Destructors have no parameters and no return type declaration, so destructors cannot be overloaded.

The destructor is automatically called when the object is destroyed.

Destructor definition guidelines: When a class has a custom constructor, and the constructor uses system resources (such as memory application, file open), you need to customize the destructor.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325884741&siteId=291194637