+ 1

What is constructor and destructor in c++?

14th Sep 2017, 4:45 PM
Bhupendra Dangwal
Bhupendra Dangwal - avatar
3 Answers
+ 4
Constructor:Destructor Purpose: Constructor is used to initialize the instance of a class. Destructor destroys the objects when they are no longer needed.When Called Constructor is Called when new instance of a class is created. Destructor is called when instance of a class is deleted or released. Memory Management: Constructor allocates the memory. Destructor releases the memory. Arguments: Constructors can have arguments. Destructor can not have any arguments. Overloading: Overloading of constructor is possible. Overloading of Destructor is not possible. Name: Constructor has the same name as class name. Destructor also has the same name as class name but with (~) tiled operator. Syntex: ClassName(Arguments) { //Body of Constructor } Destractor syntex. ~ ClassName() { }
2nd Feb 2018, 6:05 AM
Gajendra Parmar
Gajendra Parmar - avatar
0
constructor is used to initialize the instance of a class.
6th Feb 2018, 12:02 PM
Ashok Sabar
Ashok Sabar - avatar
0
Destructor destroys the objects when they are no longer needed.
6th Feb 2018, 12:04 PM
Ashok Sabar
Ashok Sabar - avatar