【发布时间】:2017-12-18 16:47:46
【问题描述】:
所以这段代码作为一个例子很好用:
#ifdef DEBUG
#define DECLARE_DEBUG_PARAM(x) x
#define PASS_DEBUG_PARAM(x) x
#else
#define DECLARE_DEBUG_PARAM(x) void
#define PASS_DEBUG_PARAM(x)
#endif
int foo(DECLARE_DEBUG_PARAM(const bool param)) {
#ifdef DEBUG
if(param) {
cout << "DEBUG true\n";
} else {
cout << "DEBUG false\n";
}
#else
cout << "RETAIL\n";
#endif
}
int main() {
foo(PASS_DEBUG_PARAM(true));
}
但我想将它用于第二个参数,例如:int foo(const int param1, DECLARE_DEBUG_PARAM(const int param2)) 显然这不适用于我当前的DECLARE_DEBUG_PARAM 定义,我收到错误:
错误:在参数声明中无效使用类型
void
是否有一些我可以使用的 noop 参数类型允许这样做?
【问题讨论】:
标签: c++ parameters macros parameter-passing precompile