title: Explicitly disallow heap allocation in C++
body: <p>I have a number of classes that I would like to explicitly disallow heap allocation for. It occurred to me this weekend that I could just declare operator new private (and unimplemented)... Sure enough, this results in compile errors when you attempt to new the class... My question is: Is there more to this? Am I missing something or is this a good way of doing what I want?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  class NotOnTheHeap
  {
  public:
    NotOnTheHeap() : foo( 0 )
    {
    }
  
  private:
    void *operator new( size_t );
    void operator delete( void* );
    void *operator new[]( size_t );
    void operator delete[]( void* );
  
    int foo;
  };
  
  class Heapable
  {
  private:
    NotOnTheHeap noth;
  };
  
  int main( int argc, char* argv[] )
  {
    NotOnTheHeap noth;
  
    Heapable* heapable = new Heapable;
  
    return 0;
  }
  </code></pre>