C++ Constructors and destructors.Constructors is a special member function of a class that gets invoked when object of its class is created. It is used to initialize the object of its class. We can also pass initial values to Constructor function at the time of object declaration.
The name of the constructor is same as that of class.
Types of Constructors
Do nothing constructor: It doesn't contain any statement, has no argument and no return type.
Default constructor: It can have some initial statements but no parameters and arguments.
Parameterized constructor: It has parameters that can set initial values to an object at the time of declaration.
Copy constructor: It takes an object as an argument and is used to copy values of data members of one object into another object.
Destructors are used to destroy the objects that have been created by the constructor. Destructor names are same as the class, but they are preceded by a tilde (~).
|