I am trying to learn the best habits and practices in C++, particularly surrounding memory management. I have been spoiled on this front by using ARC in my iOS apps, and the built-in GC in Java, as well as a few other languages where GC is enabled.
I understand that you use delete
or delete[]
to deconstruct pointers. My question is, how do you delete
integers, or other variables of a base data type?
My first thought was that since delete
seems to only work with pointers, can I do this:
int intToDelete = 6;
delete &intToDelete;
So basically, can you create a pointer to an integer in memory, and delete the integer using that pointer?