【问题标题】:A variable/data member of a class declared constexpr in C++17 is also static?在 C++17 中声明为 constexpr 的类的变量/数据成员也是静态的吗?
【发布时间】:2021-09-30 10:04:52
【问题描述】:

我没有弄清楚constexpr 在 C++17 中是否也暗示了static

我找到了这个帖子:constexpr vs. static const: Which one to prefer?

我注意到了这条评论:

One more thing, in C++17, constexpr static data member variables will be inline too. That means you can omit the out of line definition of static constexpr variables, but not static const.

上面评论中的逻辑是否暗示 constexpr 在 C++17 中也有 static 属性?

我开一个关于这个主题的新帖子的原因是有一些清楚的东西。

从我设法调查的情况来看,我认为 constexprstatic 是分开的。

对不起,如果问题没有很好地表述或很好。

【问题讨论】:

  • 你不能在类中定义非staticconstexpr变量。

标签: static c++17 constexpr


【解决方案1】:

constexpr 变量的唯一隐式存储属性是inline,并且只有当它是constexpr static 变量时才如此。成员

你不能声明一个非静态的constexpr成员变量,但static不是隐含的;这是一个明确的要求。

【讨论】:

  • 对于非成员变量,假设全局变量xconstexpr xstatic constexpr x 是两个不同的东西,不是吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-10
  • 1970-01-01
  • 2018-10-30
相关资源
最近更新 更多