Listing 1 MFC overloading of new for debugging

#include <stdlib.h>
// MFC style debug new defines.

class CObject
{
public:
#ifdef _DEBUG
       // for file name/line number tracking using DEBUG_NEW
       void* operator new(size_t nSize,
                       char * lpszFileName, int nLine);
#endif
};

#ifdef _DEBUG
// Memory tracking allocation
#define DEBUG_NEW new(__FILE__, __LINE__)
#else
// NonDebug version that assume everything is OK
#define DEBUG_NEW new
#endif

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

main()
{
       CObject *obj = new CObject;
}
// End of File