全局重载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;
}

  

posted @ 2012-09-20 20:59  特洛伊人  阅读(299)  评论(0编辑  收藏  举报