【发布时间】:2012-07-10 03:16:55
【问题描述】:
使用 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
}
【问题讨论】:
-
为什么不能对 .cpp 文件中的函数定义本身这样做?
-
foo 是在其他地方声明的类的静态成员函数吗?
-
神秘 - 我得到一个没有生成目标文件的错误 H3nr1x - 不,它只在这个类中声明
标签: c++ visual-c++ macros