+ 1

Constructor and destructor

Can someone clear me what actually the constructor and destructor is? With example and detailed. How it is important?

16th Nov 2016, 4:14 PM
Aakash Thapa
Aakash Thapa - avatar
1 Resposta
+ 6
A constructor is a special method, which runs code when an object is instantiated. A destructor is a similar method, but it runs when an object is deleted. This occurs when the program runs outside the object's scope. Destructors mainly clear out memory the unused object would have taken up. They can also run whatever code you type in it. Some languages make a default destructor for classes automatically, but C++ does not.
16th Nov 2016, 8:25 PM
Tamra
Tamra - avatar