[英]How do I use a macro to redefine a function in release mode?
使用C ++,我需要一个宏来替换一个函数,如果它在发布模式下运行,它什么都不做。 因此,在调试模式下,该函数将被执行,但在释放模式下则不会。
像这样的东西:
static void foo(int,int)
#ifdef NDEBUG
#define foo(x,y)
#endif
...并且函数体在一个单独的.cpp文件中定义,并且是类的一部分,这就是为什么我认为这不起作用?
实际代码..
头
static void ValidateInput(const SeriesID *CurrentSeries, const AEnum_TT_TICK_ROUND& roundType = TT_TICK_ROUND_NONE);
的.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
}
static void foo(int,int); // declaration
// Definition in your cpp file.
void foo( int x, int y )
{
#ifndef NDEBUG
// Code for debug mode
#endif
}
static void foo_(int, int);
#ifdef NDEBUG
#define foo(x,y)
#else
#define foo(x,y) foo_(x,y)
#endif
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.