在尝试重写global new/delete 操作符进行调试工作时,发现如果程序使用MFC并且采用“Use MFC in a static library”方式时,会产生链接错误,如下所示:
1>uafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in MemoryAllocFunc.obj
1>uafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in MemoryAllocFunc.obj
1>uafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new[](unsigned int)" (??_U@YAPAXI@Z) already defined in MemoryAllocFunc.obj
1>uafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete[](void *)" (??_V@YAXPAX@Z) already defined in MemoryAllocFunc.obj
将工程类型修改成“Use MFC in a Shared DLL”方式后,即可解决该错误,重写的全局new/delete操作可正常工作。
附代码:http://download.csdn.net/detail/tzxx/9726975