新的定义

Hab*_*bit 1 c++ memory memory-leaks detect

今天,我找到了有关内存泄漏检测的源代码,并且在他的头文件中,我找到了以下宏定义,有人可以告诉我这是什么意思吗?谢谢!

#ifndef MC_NO_REDEFINITION
    #define new MC_NEW
    #define MC_NEW new(__FILE__,__FUNCTION__,__LINE__)
        #define mc_new new
else
//use defined function name instead of keyword new & delete
    #define debug_new new(__FILE__,__FUNCTION__,__LINE__)
#endif  
Run Code Online (Sandbox Code Playgroud)

这意味着new表示new(__FILE__,__FUNCTION__,__LINE__),如果这是真的,那么当我在代码中使用new时,编译器如何知道我真正想要调用的东西?

Ker*_* SB 5

提供这些宏的相同代码还必须提供适当的全局定义,该定义operator new()采用适当的附加参数,例如:

void * operator new(std::size_t n, char const * file, char const * func, char const * line)
{
    // log file, func, line

    return operator new(n);
}
Run Code Online (Sandbox Code Playgroud)

还应该有一个匹配项operator delete()

请注意,这new是一个关键字,我认为标准实际上并不宽容用宏替换关键字。