title: why overloaded new operator is calling constructor even I am using malloc inside overloading function?
body: <p>I am trying to understand overloading new operator. I wrote the code as below.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  #include &lt;new&gt;
  
  using namespace std;
  
  class loc
  {
      int lo, la;
  
      public:
          loc()
          {
          }
  
          loc(int x, int y)
          {
              cout &lt;&lt; "In constructor\n";
              lo = x;
              la = y;
          }
  
          void show()
          {
              cout &lt;&lt; lo &lt;&lt; " ";
              cout &lt;&lt; la &lt;&lt; endl;
          }
  
          void *operator new(size_t sz);
          void operator delete(void *p);
  };
  
  void *loc::operator new(size_t sz)
  {
      cout &lt;&lt; "in Overloaded new\n";
      void *p = malloc(sz);
  
      return p;
  }
  
  void loc::operator delete(void *p)
  {
      cout &lt;&lt; "in Overloaded delete\n";
      free(p);
  }
  
  int main()
  {
      loc *p1 = new loc(10, 20);
      p1-&gt;show();
      delete p1;
      return 0;
  }
  </code></pre>
  
  <p>I thought it won't call the constructor because I overloaded the new operator with malloc function call inside overloading function. But the output is as below.</p>
  
  <pre><code>in Overloaded new
  In constructor
  10 20
  in Overloaded delete
  </code></pre>
  
  <p>That means constructor is getting called. How this is possible? Does this mean will malloc() call constructor?</p>