Why doesn't this work?



1
2
3
4
//Why can i do this to de-allocate from the heap,
char * p = new char[20];
void *i = p;
delete[](char*)i;

1
2
3
4
5
6
//but not this?
//Can you explain?
char * p = new char[20];
unsigned long x = (unsigned long)p;
void *i = i;
delete[](char*)i;
Is it a typo?

void *i = i;
Is it a typo?


Yes, and not it works. Thank you.

1
2
3
4
char * p = new char[20];
unsigned long x = (unsigned long)p;
void *i = (void*)x;
delete[](char*)i;
Topic archived. No new replies allowed.