我在代码中使用了const变量。并想告诉我的预处理器使用它。即:
const double x = 1.2; const bool xIsZero = x==0; #if xIsZero ... #endif
但是那不起作用。在C ++ 17中,
if constexpr
没有用。但是我暂时还停留在C ++ 11上。
因此,我可以使用类似的解决方法:
#define X 1.2 #define xIsZero (x==0) const double x = X; #if xIsZero ... #endif
但是我只是不喜欢将x赋予#define,我想直接将其赋予const。有办法吗?
我在代码中使用了const变量。并想告诉我的预处理器使用它。即:const double x = 1.2; const bool xIsZero = x == 0; #if xIsZero ... #endif但这不起作用。在C ++中...
如果条件在编译时是已知的,则可以使用重载来模拟C ++ 11中的if constexpr
: