Reputation: 283
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
}
Upvotes: 2
Views: 1706
Reputation: 1531
static void foo(int,int); // declaration
// Definition in your cpp file.
void foo( int x, int y )
{
#ifndef NDEBUG
// Code for debug mode
#endif
}
Upvotes: 5
Reputation: 375764
static void foo_(int, int);
#ifdef NDEBUG
#define foo(x,y)
#else
#define foo(x,y) foo_(x,y)
#endif
Upvotes: 4