我知道 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();
关于c++ - static const 和 constexpr 变量有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23538440/