title: Why doesn't overloading operator new with std::string work with msvc /MD flag
body: <p>I have some code that looks like this.</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  void* operator new(std::size_t n){
      std::cout &lt;&lt; "[Allocating " &lt;&lt; n &lt;&lt; "bytes] ";
      return malloc(n);
  }
  
  void operator delete(void* pointer) throw() {
      free(pointer);
  }
  
  int main(){
  
      for(int i = 0; i &lt; 24; i++){
          std::cout &lt;&lt; i &lt;&lt; ": " &lt;&lt; std::string(i, '=') &lt;&lt; std::endl;
      }
  
  }
  </code></pre>
  
  <p>this compiles and runs using gcc compiler and also runs when using msvc compiler with the flag /MT or /MTd set. however if I set the flag to /MDd or /MD The program crashes. It seems to be stuck in a recursion inside the new operator. Why doesn't this happen when compiling and linking against LIBCMT.lib  which as I can tell from Microsoft docs is the difference between /MT and /MD.</p>