How to delete an object in C++? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to delete an object in C++?

Hi, I need to destroy an non-pointer object, but I couldn't find any answer. Could you help me please?

27th May 2021, 6:39 PM
Żab00l
Żab00l - avatar
3 Answers
+ 2
You can't. But why do you want to? You could assign something else to it, which will delete the previous object, but really, what's the point?
27th May 2021, 8:31 PM
XXX
XXX - avatar
+ 2
Instead of deleting it, assign new value to the object. You can also try separating scopes if it is possible in your code. Cuz you should know that variable lives in the scope in which it is declared only
28th May 2021, 12:54 AM
Michal Doruch
0
XXX I want to make another object with different value, but I won't Loss memory for existence of older objects
27th May 2021, 8:34 PM
Żab00l
Żab00l - avatar