title: Why is the delete operator required to be static?
body: <p>I found <a href="https://stackoverflow.com/questions/2141023/do-the-class-specific-new-delete-operators-have-to-be-declared-static">this one question asking the same thing</a>, however only the 'new' part was answered, so here goes again.</p>
  
  <p>Why is the delete operator required to be static? Somehow it doesn't make sense. The new operator makes perfect sense, just like the constructor can't be virtual, neither can the new operator. However, the destructor can (and should) be virtual when you use inheritance, in order to allow destruction of objects being used (by way of polymorphism) as a base class.</p>
  
  <p>I understand that, when the delete operator is called, the object has already been destroyed, so no 'this' exists. Yet it still makes sense, using the same reasoning as with virtual destructor, to have the delete operator match the new operator which created the object.</p>
  
  <p>This is what I mean</p>
  
  <pre><code>class A
  {
    public:
      virtual ~A() {}
  };
  
  class B : public A
  {
    public:
      void* operator new (size_t sz);
      void  operator delete (void* ptr, size_t sz);
  };
  </code></pre>
  
  <p>now if we do</p>
  
  <pre><code>A *ptr = new B();
  delete ptr; // &lt;-- fail
  </code></pre>
  
  <p>A's delete operator (default) should've been called, since it's static and it's not known (for anything but the trivial case here) at compile time which delete-operator is the correct one.</p>
  
  <p>However, I made a small test program with the code above (just malloc/free in the new/delete operators, and print statement in delete), and compiled it using g++. Running it quite unexpectedly produced the output in B's delete operator.</p>
  
  <p>My (real) question is this: Is there some implicit 'virtualness' to the delete operator? Is it only static in the no-this-pointer sense? Or is this just a g++ feature?</p>
  
  <p>I started looking through the C++ specification, but I must admit, I was bit overwhelmed by it, so any help appreciated.</p>