Bul*_*127 2 c++ macros visual-c++
使用C++,我需要一个宏来替换一个函数,如果它在发布模式下运行,它什么都不做.因此,在调试模式下,该函数将被执行,但在释放模式下则不会.
像这样的东西:
static void foo(int,int)
#ifdef NDEBUG
#define foo(x,y)
#endif
Run Code Online (Sandbox Code Playgroud)
...并且函数体在一个单独的.cpp文件中定义,并且是类的一部分,这就是为什么我认为这不起作用?
实际代码..
头
static void ValidateInput(const SeriesID *CurrentSeries, const AEnum_TT_TICK_ROUND& roundType = TT_TICK_ROUND_NONE);
Run Code Online (Sandbox Code Playgroud)
的.cpp
void TTBaseTick::ValidateInput(const SeriesID *CurrentSeries, const AEnum_TT_TICK_ROUND& roundType)
{
#ifndef _DEBUG
if (!CurrentSeries)
{
throw TTTick::Ex(TTTick::SeriesNull);
}
else if (CurrentSeries->precision <= 0)
{
throw TTTick::Ex(TTTick::PrecisionInvalid);
}
else if(!roundType.IsValidValue(roundType))
{
throw TTTick::Ex(TTTick::InvalidParam);
}
#endif
}
Run Code Online (Sandbox Code Playgroud)
static void foo(int,int); // declaration
// Definition in your cpp file.
void foo( int x, int y )
{
#ifndef NDEBUG
// Code for debug mode
#endif
}
Run Code Online (Sandbox Code Playgroud)