我在我的代码中使用了一个 const 变量。并想告诉我的预处理器使用它。即:
const double x = 1.2;
const bool xIsZero = x==0;
#if xIsZero
...
#endif
Run Code Online (Sandbox Code Playgroud)
但这不起作用。在 C++ 17 中,if constexpr没有诀窍。但我现在坚持使用 C++11。
因此,我可以使用以下解决方法:
#define X 1.2
#define xIsZero (x==0)
const double x = X;
#if xIsZero
...
#endif
Run Code Online (Sandbox Code Playgroud)
但我只是不喜欢将 x 赋予 #define,我想直接将其赋予常量。有没有办法做到这一点?