+ 3

What was difference between destructors and contractors

Since destructors can't take parameters, they also can't be overloaded. Each class will have just one destructor.

2nd Jan 2017, 11:41 PM
Mohammed Al-Ajlouni
Mohammed Al-Ajlouni - avatar
3 Réponses
+ 2
in the constructors you create the objects by saving their data in memory. in the destructor you delete the objects data from the memory. you can have different constructors because you can create an object from different type of data. but you can only destroy a created object in one way, by deleting all of its data from memory.
2nd Jan 2017, 11:53 PM
DFX
DFX - avatar
+ 1
both are member function of class with the class name only.but constructor is specified with return type statement but destructor is not specified with any return type statement.constructor gets invoked when its object is created whereas destructor gets invoked when object goes out of scope
28th Jan 2017, 3:01 PM
Mayank Raj
Mayank Raj - avatar
+ 1
Basically constructor is use to initialize the value ,so we can use it for initialize value.And destructor is use for deallocate the memory to the variable
29th Jan 2017, 9:15 AM
Dhiraj Ramteke
Dhiraj Ramteke - avatar