How does "delete" work?

Hi all,

I am quite confused about how "delete" works.

If I have a class like

class test {
char zip[5];
other_class *to_somewhere;
test *next;
};
.....
test *x = new test;
.....
delete x;

My questions are:
1. will "zip" be freed? if not, how can I delete those characters when x got deleted?
2. will both blocks of memory pointed by "to_somewhere" and "next" be freed? or just "to_somewhere" and "next" that will be deleted?

Thank you in advance
Last edited on
1. Yes.
2. Not if you didn't write your own destructor that does it.
I see. Thank you very much, helios.
closed account (S6k9GNh0)
That didn't answer question two I don't believe. If you assign dynamically allocated memory to the pointers, they will not. But if they are never assigned to anything they will be deleted when out of scope.
Topic archived. No new replies allowed.