How to delete object constructed via placement new operator?
问题 char * buf = new char[sizeof(T)]; new (buf) T; T * t = (T *)buf; //code... //here I should destruct *t but as it is argument of template and can be //instantiated via basic types as well (say int) so such code /*t->~T();*/ //is incorrect (maybe correct? Strange, but it works on VS 2005 for basic types.) //and this code /*delete t;*/ //crashes the program. delete [] buf; So what is correct way to destruct t ? P.S. The code above is only for describing my problem, and have not real relationship