I have a doubt that if I made a constructor and If I don’t write line no. 14 and 15 then program does not work correctly so if I similarly make a destructor and I write only “Inside destructor” in it then program runs.
So here 3 doubts arises :-
First, will object will be deleted if I have overwritten destructor and I have not written any logic to delete object.
Second, why without line 14 and 15 program not works.
Third, the overwritten copy constructor not works if I have not written the constructor. Why??
Regarding Destructor and Constructor
ya so basically if u dint write line 14 and 15 it will give garbage value only as nothing is being assigned then…
overwritten copy constructor not works if I have not written the constructor–> for this u have to make a constructor only then it will work…
And what about destructor ( doubt 1)
and what about destructor (doubt 1)
means if I have not written any logic for deletion of object in ~Car then will it delete object or not?
You should have destructor when your class is allocating dynamic memory. If it doesn’t, default destructor will be generated for you and it will do the work .
No actually I want to ask that when we overwrite copy constructor then it works if we have written some logic for copying and we have not written any thing then it does not work because we have overwritten default copy constructor and now we don’t have done anything in it. So, if I have overwritten the default destructor without any logic for deletion in it , then how can objects will be deleted ??
Refer to line 18 to 20 in program no. 607985
Please resolve my doubt
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.