I have some code that looks like this.
#include <iostream>
#include <string>
void* operator new(std::size_t n){
std::cout << "[Allocating " << n << "bytes] ";
return malloc(n);
}
void operator delete(void* pointer) throw() {
free(pointer);
}
int main(){
for(int i = 0; i < 24; i++){
std::cout << i << ": " << std::string(i, '=') << std::endl;
}
}
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.
operator deletemarkedthrowand youroperator newnot?