簡體   English   中英

如何使用宏在發布模式下重新定義函數?

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM