静态constexpr全局变量[重复项]

问题描述 投票:1回答:2

在C ++ 17中,这样声明全局常量之间没有任何区别:

namespace ns
{
static constexpr const auto global_variable = 47;
}

还要同时指定const修饰符,以及:

namespace ns
{
static constexpr auto global_variable = 47;
}

没有指定const?如果是,则在哪些情况下有哪些区别以及建议使用哪个版本的声明?

c++ static global-variables const constexpr
2个回答
0
投票

您在这里不需要constconstexpr表示const


0
投票

没有区别,对象类型变量的constexpr说明符表示const [dcl.constexpr]/9

在对象声明中使用的constexpr说明符将对象声明为const

© www.soinside.com 2019 - 2024. All rights reserved.