First, the constructor function and the destructor
Reference Link: http://www.cnblogs.com/mr-wid/archive/2013/02/19/2917911.html
1. Constructors
constructors are primarily used to perform some initialization of object properties when an object is created, and when an object is created, the object automatically calls its constructor. In general, constructors have the following three functions:
- Establishes an identifier for the created object;
- Open up memory space for object data members;
- Completes initialization of the object data member.
2. Destructors
The destructor, in contrast, is called automatically when an object is revoked, for some cleanup work when the member is revoked, such as the previously mentioned manual release of the requested memory space using new or malloc. Destructors have the following characteristics:
The destructor function name is the same as the class name, and it is closely preceded by the name with the tilde ~ and the constructor, for example: ~point ();
Constructors have no return type and cannot specify parameters, so destructors can only have one and cannot be overloaded;
Destructors are called automatically when an object is revoked, and unlike constructors, destructors can be explicitly called to free memory that is dynamically requested in the object.
Constructors and destructors