The constructor is initialized automatically when the class object is created, not by the interface user invoking the function itself.
The destructor is for the final cleanup work when the class object expires. In summary, it is the function that is called when the object is destroyed.
Note: Constructors and destructors do not have return values and claim types
constructor function:
Declaration method:
1 class_name::class_name (...) {...} // same as normal function but the function name must be the same as the class name
Calling method: Class_name class = Class_name (...);
Class_name class (...);
Use NEW:
Class_name * class = new class_name (...);
Default constructor: To create a constructor for an object without providing the initial value of the display, typically the compiler uses the default constructor by default when no declaration is made to define the constructor.
There are two ways to define this: 1. Provides default parameters for all parameters of an existing constructor.
2. Use a function overload to define another constructor ———— a constructor with no arguments. ( common )
Destructors:
Class_name::~class_name (...) {...};
Constructors and destructors for classes