
4 Jan
2010
4 Jan
'10
6:08 p.m.
Stefan Strasser wrote:
quick question about this, is it legal to do the following?
T *t=reinterpret_cast<T *>(new char[sizeof(T)]); new (&t) T; delete T;
No, because memory allocated with new[] must be deallocated with delete[]. T *t=static_cast<T *>( operator new( sizeof(T) ) ); takes care of this. There'd still be a mismatch if T had class-specific operator new/delete though, unless one is careful to use ::delete.