Possible Duplicate:
Is it safe to delete a void pointer?
Will the following code cause memory leak?
void *ptr = new long [10];
delete[] ptr; // note: ptr is a void*
[EDIT]
The code above will generate a warning message during compiling to specify it “undefined”.
I ask this cause I’m wondering how does C++ handle memory ranges when delete[] is called.
I should change my question to make it more specified.
Will the following code cause memory leak?
char *ptr = (char *)(new long [10]);
delete[] ptr; // note: ptr is a char*
No. Leaving
delete[]out will cause a leak. BTW, it should belong* ptr. I don’t think thedelete[]will even compile with avoid*argument.