#if !defined(_Debug_New_Defined_)
#define _Debug_New_Defined_
#if defined(_DEBUG)
#include <crtdbg.h>
static class CRT_MEMORY_CHECK
{
public:
CRT_MEMORY_CHECK()
{
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
}
} _crt_momory_chekc;
void* operator new(size_t size, const char* filename, int line)
{
printf("operator new() calles\n");
printf("%s(%d)\n",filename, line);
return ::operator new(size, _NORMAL_BLOCK, filename, line);
}
#define THIS_FILE __FILE__
#define DEBUG_NEW new(THIS_FILE, __LINE__)
#endif
#endif
////////////////
#include "stdafx.h"
#include "Debug_New.h"
#if defined(_DEBUG)
#define new DEBUG_NEW
#endif
#define DEBUG //주석처리하면 scanf 실행되지 않음
void main()
{
int* p = new int();
*p=1;
printf("%i\n",*p);
delete p;
#ifdef DEBUG
//cmd
char c;
scanf("%c",&c);
#endif
}
