title: Detecting stack or heap allocation
body: <p>I have a class I’d like to be able to set a flag in that says if it is heap allocated so it can properly clean up after itself and not try to delete itself if it’s on the stack. The problem is...I can’t seem to override both <code>new</code> and the constructors at the same time. So it goes from my <code>new</code> overload that sets the <code>isHeapAllocated</code> flag and then into my constructor which resets the flag.</p>
  
  <pre><code>void* String8::operator new(size_t size)
  {
      String8* string = (String8*)malloc(size);
      if(string == null)
          Exception("allocation fail : no free memory");
      string-&gt;isHeapAllocated = true;
      return string;
  }
  
  String8::String8() 
  {
      isHeapAllocated = false;
  }
  </code></pre>
  
  <p>So <code>new String8()</code> sets the <code>isHeapAllocated</code> flag and then resets it to <code>false</code>. Is there any way to do this?</p>