我知道
constexpr
variable 可以在编译时使用。
例如,对于模板或静态断言器。
但是如果我想在没有 constexpr 的情况下做到这一点,我可以使用
static const
。
自 C++11/14 引入 constexpr 以来有何区别
constexpr int a = 3;
//AND
static const int a = 3;
谢谢!
查看这个问题的另一种方式是我应该使用哪个?
我知道的主要区别是,
constexpr
的值必须在编译时已知,而const static
可以在运行时分配。
const static int x = rand();