title: Call destructor and then constructor (resetting an object)
body: <p>I want to reset an object. Can I do it in the following way?</p>
  
  <pre><code>anObject-&gt;~AnObject();
  anObject = new(anObject) AnObject();
  // edit: this is not allowed: anObject-&gt;AnObject();
  </code></pre>
  
  <p>This code is obviously a subset of typical life cycle of an object allocated by in placement new:</p>
  
  <pre><code>AnObject* anObject = malloc(sizeof(AnObject));
  anObject = new (anObject) AnObject(); // My step 2.
  // ...
  anObject-&gt;~AnObject(); // My step 1.
  free(anObject)
  // EDIT: The fact I used malloc instead of new doesn't carry any meaning
  </code></pre>
  
  <p>The only thing that's changed is the order of constructor and destructor calls.</p>
  
  <p>So, why in the <a href="http://yosefk.com/c++fqa/dtor.html#fqa-11.9" rel="noreferrer"> following FAQ </a> 
  all the threatening appear? </p>
  
  <blockquote>
    <p>[11.9] But can I explicitly call a
    destructor if I've allocated my object
    with new?</p>
    
    <p>FAQ:  You can't, unless the object was
    allocated with placement new. Objects
    created by new must be deleted, which
    does two things (remember them): calls
    the destructor, then frees the memory.</p>
    
    <p>FQA: Translation: delete is a way to
    explictly call a destructor, but it
    also deallocates the memory. You can
    also call a destructor without
    deallocating the memory. It's ugly and
    useless in most cases, but you can do
    that.</p>
  </blockquote>
  
  <p>The destructor/constructor call is obviously normal C++ code. Guarantees used in the code directly result from the in placement new guarantees. It is <strong>the core of the standard</strong>, it's rock solid thing. How can it be called "dirty" and be presented as something unreliable?</p>
  
  <p>Do you think it's possible, that the in-placement and non-in-placement implementation of new are different? I'm thinking about some sick possibility, that the regular new can for example put size of the memory block allocated before the block, which in-placement new obviously would not do (because it doesn't allocate any memory). This could result in a gap for some problems... <strong>Is such new() implementation possible?</strong></p>