{"id":3881,"date":"2014-03-30T06:10:40","date_gmt":"2014-03-30T06:10:40","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-delete-object-constructed-via-placement-new-operator-collection-of-common-programming-errors\/"},"modified":"2014-03-30T06:10:40","modified_gmt":"2014-03-30T06:10:40","slug":"how-to-delete-object-constructed-via-placement-new-operator-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-delete-object-constructed-via-placement-new-operator-collection-of-common-programming-errors\/","title":{"rendered":"How to delete object constructed via placement new operator?-Collection of common programming errors"},"content":{"rendered":"<pre><code>char * buf = new char[sizeof(T)];\nnew (buf) T;\nT * t = (T *)buf;\n\/\/code...\n\/\/here I should destruct *t but as it is argument of template and can be\n\/\/instantiated via basic types as well (say int) so such code \n\/*t-&gt;~T();*\/\n\/\/is incorrect (maybe correct? Strange, but it works on VS 2005 for basic types.)\n\/\/and this code \n\/*delete t;*\/ \n\/\/crashes the program.\ndelete [] buf;\n<\/code><\/pre>\n<p>So what is correct way to destruct <code>t<\/code>?<\/p>\n<p>P.S. The code above is only for describing my problem, and have not real relationship with code I&#8217;m going to write. So please don&#8217;t give answers like (<code>Why use placement new instead of non-placement?<\/code> or something similar)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>char * buf = new char[sizeof(T)]; new (buf) T; T * t = (T *)buf; \/\/code&#8230; \/\/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-&gt;~T();*\/ \/\/is incorrect (maybe correct? Strange, but it works on VS 2005 for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3881","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3881","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3881"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3881\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3881"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3881"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3881"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}