Difference between Constructors and Destructors
Constructor
Constructors are special member functions of a class which is used to initialize the object in desired way. Constructors has the same name as that of class. There could be multiple constructors defined in a class which could be selected based on invoking conditions.
Types of constructor
- Default constructor – Any constructor without argument is called default constructor.
- Parameterized constructor – Any constructor in which argument can be passed is called Parameterized constructor.
- Copy constructor – This is a special kind of constructor which uses an existing object to create a new object.
Destructor
Destructor is a special member function of a class which is used to delete the object. Destructor also has the same name as that of class prefixed with “~” sign. In any class, one could define only one destructor. Destructor doesn’t take any argument.
(more…)