+ 1

What is diffrence between constructor and destructor in C++?

Object-oriented programming

26th Aug 2017, 3:09 PM
Ulaankhuu Bymbasuren
Ulaankhuu Bymbasuren - avatar
2 Réponses
+ 6
Constructor is used to initialize the instance of a class while Destructor destroys the objects when they are no longer needed. Constructor is Called when new instance of a class is created while Destructor is called when instance of a class is deleted or released. Constructor allocates the memory while Destructor releases the memory.
26th Aug 2017, 3:15 PM
Ankit Saxena
Ankit Saxena - avatar
+ 1
Constructor: executed when an object is created. Destructor: executed when an object is destroyed. You cannot take arguments for a destructor. If you don't know what an object is yet, you don't need to worrie about these right now.
26th Aug 2017, 3:11 PM
Jordan Chapman
Jordan Chapman - avatar