int* x = new int[0];
, 'x' is not NULL. Do you still need to 'delete[]' it, even though no useable memory was allocated?
C++: have to 'delete[]' after using 'new T[0]'?
Should be a simple question, but I haven't been able to find the answer. If you do
Been a long time since I used C++ so I really don't remember but my general rule of thumb is if I can't find something explicitly stating what should happen then it is by definition undefined behavior. In that case you just shouldn't do it.
[edit] SiCrane with the ninja.
It states here that the only legal and in fact <required> operation is to delete[] it.
http://stackoverflow.com/questions/1087042/c-new-int0-will-it-allocate-memory
[edit] SiCrane with the ninja.
It states here that the only legal and in fact <required> operation is to delete[] it.
http://stackoverflow.com/questions/1087042/c-new-int0-will-it-allocate-memory
WHENEVER you use new like this :
dataType heap = new dataType; (i.e no brackets)
you accompany it by using delete heap;
and WHENEVER you use brackets with new like this :
dataType heap2 = new dataType[someNumber]; (i.e new with brackets)
you need to accompany new with delete [] heap2 after your done.
dataType heap = new dataType; (i.e no brackets)
you accompany it by using delete heap;
and WHENEVER you use brackets with new like this :
dataType heap2 = new dataType[someNumber]; (i.e new with brackets)
you need to accompany new with delete [] heap2 after your done.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement