全局重载new运算符
#include <stdio.h> #include <malloc.h> void* __cdecl operator new( unsigned int size, const char *p, int line) { printf("the file :%s\n", p); printf("the line: %d\n", line); void *ret = malloc(size); return ret; } #define new new(__FILE__, __LINE__) int _tmain(int argc, _TCHAR* argv[]) { int *p = new int; printf("Hello World!\n"); return 0; }