Xdebug Errors: xdebug(32) : error C2365: 'operator new' : redefinition; previous definition was 'function'

      今天合代码的时候,报了一堆如下的错误,折腾了半个小时才搞明白……

Xdebug Errors: xdebug(32) : error C2365: 'operator new' : redefinition; previous definition was 'function'_第1张图片

      咋一看莫名其妙,后来仔细看了xdebug里面的代码,有如下的定义:

#if defined(_DEBUG) #define _NEW_CRT new(std::_DebugHeapTag_func(), __FILE__, __LINE__) #define _DELETE_CRT(ptr) std::_DebugHeapDelete(ptr) #define _DELETE_CRT_VEC(ptr) std::_DebugHeapDelete((void *)ptr) #define _STRING_CRT _DebugHeapString #include <crtdbg.h> #include <xmemory> #include <xstring> _MRTIMP2 __bcount(_Size) void * __cdecl operator new(size_t _Size, const std::_DebugHeapTag_t&, __in_z_opt char *, int) _THROW_BAD_ALLOC; // allocate from the debug CRT heap ……

      在_DEBUG下new被重定义了(用来检测内存泄漏),然后查了下自己的代码,发现也有new的新定义……,因为之前是从MFC下面迁移过来的代码:

#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif

      杯具……又是混用MFC和标准库造成的。

 

      解决方法也就明朗了。

      方法一:把所有文件里面上面的那一堆“……#define new DEBUG_NEW……”全部删除

      方法二:要么就保证使用了new的语句在上面的那一坨宏的前面。

      个人建议还是全删了吧。

你可能感兴趣的:(c,String,function,File,delete,mfc)