简体   繁体   中英

How do I use a macro to redefine a function in release mode?

Using C++, I need a macro that will replace a function to do nothing if it is running in release mode. So, in debug mode the function will be executed, but in release mode it will not.

Something like this:

static void foo(int,int)

#ifdef NDEBUG
#define foo(x,y)
#endif

...and the function body is defined in a separate .cpp file and is part of a class, which is why I think this isn't working?

actual code..

header

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM