VS2008到VS 2010的迁移 - 一个突破性的变化?

Mos*_*hik 2 c++ visual-studio-2010 visual-c++-2010

我将C++代码从VS2008迁移到VS2010时遇到了问题.到目前为止,我无法找到解释原因,并感谢您的帮助.

我们有一个自定义内存分配器,它驻留在一个DLL中.在其余的代码中,我们使用预处理器将分配重定向到我们的函数.以下简单代码在VS2008中正确编译,但在VS2010中没有.

在stdafh.h中:

#define free my_free
#include <string>
Run Code Online (Sandbox Code Playgroud)

在VS2010中,我得到:

1>d:\program files\microsoft visual studio 10.0\vc\include\xdebug(62): error C3861: 'free': identifier not found
Run Code Online (Sandbox Code Playgroud)

来自这条线:

template<class _Ty>
    void __CLRCALL_OR_CDECL _DebugHeapDelete(_Ty *_Ptr)
    {   // delete from the debug CRT heap even if operator delete exists
    if (_Ptr != 0)
        {   // worth deleting
        _Ptr->~_Ty();
        // delete as _NORMAL_BLOCK, not _CRT_BLOCK, since we might have
        // facets allocated by normal new.
        free(_Ptr);
Run Code Online (Sandbox Code Playgroud)

任何帮助或想法将受到高度赞赏!

摩西

tem*_*def 6

根据C++ ISO标准,第17.4.3.1.1.2节:

包含标头的转换单元不应包含定义在该标头中声明或定义的名称的任何宏.这样的翻译单元也不应该为与关键字词汇相同的名称定义宏.

这意味着#define库函数名称的含义不合法.我想这恰好在VS2008中工作,但是当迁移到VS2010时,编译器的作者提出了一个实现无法正常工作的实现.

如果你想重新定义free它的作用,我建议通过将代码与你自己的C库实现相关联来通过一个更传统的通道来改变默认行为.