Questions about operator new() and operator delete()
<p>Consider the following code and the questions below:</p>

<pre><code>/*
* GCC 4.4
*/
#include &lt;iostream&gt;

using namespace std;

class A {
public:

    void* operator new(size_t s) {
        cout &lt;&lt; "A::operator new(size_t) called\n";
    }

    void operator delete(void* p) {
        cout &lt;&lt; "A::operator delete(void*) called\n";
    }

    void* operator new(size_t s, A* p) {
        cout &lt;&lt; "A::operator new(size_t, A*) called\n";
    }

    void operator delete(void* p, size_t s) {
        cout &lt;&lt; "A::operator delete(void*, size_t) called\n";
    }

};

void* operator new(size_t s) {
    cout &lt;&lt; "::operator new(size_t) called\n";
}

void operator delete(void* p) {
    cout &lt;&lt; "::operator delete(void*) called\n";
}

void* operator new(size_t s, A* p) {
    cout &lt;&lt; "::operator new(size_t, A*) called\n";
}

void operator delete(void* p, size_t s) {
    cout &lt;&lt; "::operator delete(void*, size_t) called\n";
}

int main() {    
    A* p1 = new A(); // See question 1.
    delete p1; // See question 2.
    A* p2 = new (p1) A(); // See question 3.
    delete p2; // See question 4.
}
</code></pre>

<p>The questions below might seem redundant somehow. However, what I am trying to distinguish is what is defined by the C++ standard rules from what is defined by the implementation.</p>

<ol>
<li><p><code>operator new(size_t)</code> will be used in any case (taken from A or from the global
 namespace, be it default or not). This is OK.
 Now try to remove <code>void* A::operator new(size_t) {}</code> only: why does the compiler gives:</p>

<blockquote>
  <p>error: no matching function for call to ‘A::operator new(unsigned
  int)’
  note: candidates are: static void* A::operator new(size_t, A*)</p>
</blockquote>

<p>Connot the compiler pick up <code>::operator new(size_t)</code> from the global
 namespace?</p></li>
<li><p>Why is <code>operator delete(void*)</code> preferred to <code>operator delete(void*, size_t)</code>
 (when both of those versions are present in the same namespace where <code>operator delete (void*)</code> is taken from)?</p></li>
<li><p>Why will not the code compile if I remove <code>void* A::operator new(size_t, A*)</code>,
 although there is the same version of the operator defined in the global namespace?</p>

<blockquote>
  <p>error: no matching function for call to ‘A::operator new(unsigned int,
  A*&amp;)’
       note: candidates are: static void* A::operator new(size_t)</p>
</blockquote></li>
<li><p>Why does the compiler still prefer 
 <code>operator delete (void*)</code>, although <code>A::operator new(size_t, A*)</code> has been used
 for getting p2?</p></li>
</ol>
