[英]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.