only one destructor is applicable in one class as compared to constructor we can add as many with the help of overloading I just want to understand it!! can't we define the ending of the program in our own way with some conditions on to it. like we do in python with exception syntax!!
Though, from first look anyone might think that we can add arguements to destructor to make it vary. But the thing is, there is no statement to execute it. A destructor automatically initiates. So, you can not make more destructors than 1.
Hope you got it buddy.
By asking this question, you're missing the point of destructors. They exist so you don't have to worry about manually freeing your object's dynamic memory when it falls out of scope. Because they get called automatically, it wouldn't make sense to allow parameters-- How would the compiler decide what arguments to use when calling it?
If you want to have multiple "destructors" with different parameters, all you need to do is write them as member functions. You can still have your default destructor that gets called automatically in addition to whatever special disposal procedures you want to add and call manually.
PS: Contrary to the top answer right now, it is possible to call the destructor manually: "object.~Object();" is perfectly valid.
kamran, virtual destructors are absolutely deterministic and, though non trivial are a perfect counterbalance to the question. As such they really need an explanation that I shan't attempt to do justice to.
because the constructor can be many depending upon the number of arguments(parameters) but destructor is unparametersed in nature so it's enough to use once .the ultimate goal is to free the space that occupy by the constructor...and it achieve using that once
when class object initialize constructor construct on ram when you need to destroy on ram automaticaly calls destructor which func destroy initialized object of course this makes you can call them one time per object
You only do overloading because of the parameters you wanna pass into the function. Why would you wanna try overloading any function that doesn't receive arguments? Besides, Overloading allows a function to perform tasks based the arguments... Destructors have a sole purpose which is mainly to release resources and stuffs like that.
destructor must be one method. the method automatically invoked when object is died. language has automatic garbage collection feature. the feature knows only the destructor and it does not need an argument.
As function return one value
so all complier can handle is to nurture and assassinate one value only.....
however long the function may be
however long the structure may be
The variable categorisation does all the trick
The answer is easy and straightforward.If you need to construct some object you can do it by several ways(several constructors).Resources allocation and using memory of the object be changing through the life cycle of the object but destroying of the object has only one state and it is to free all allocated resources and used memory.The destroyer must make sure this state.From that reasons other destructors are wasted.If you need to keep some other info helps you to do it you can use member variables for it.