在C ++ 17中,这样声明全局常量之间没有任何区别:
namespace ns
{
static constexpr const auto global_variable = 47;
}
还要同时指定const
修饰符,以及:
namespace ns
{
static constexpr auto global_variable = 47;
}
没有指定const
?如果是,则在哪些情况下有哪些区别以及建议使用哪个版本的声明?
您在这里不需要const
,constexpr
表示const
。
没有区别,对象类型变量的constexpr
说明符表示const
[dcl.constexpr]/9:
在对象声明中使用的
constexpr
说明符将对象声明为const
。