【发布时间】:2022-01-14 13:48:03
【问题描述】:
static constexpr 和 constexpr 在函数体内使用时有什么区别吗?
int SomeClass::get(const bool b)
{
static constexpr int SOME_CONSTANT = 3;
constexpr int SOME_OTHER_CONSTANT = 5;
if(b)
return SOME_CONSTANT;
else
return SOME_OTHER_CONSTANT;
}
【问题讨论】:
-
this 函数内部或 any 函数内部的“任何区别”?
constexpr变量具有某些特性,static变量也是如此。 -
我正在寻找这个函数内部的任何区别。因为,我猜如果它们在编译时执行,即
constexpr,函数声明,一切都会有所不同。