【发布时间】:2017-10-11 06:29:49
【问题描述】:
考虑static constexpr 成员的这个用例:
// smart_enum.h
class smart_enum {
// Some data, operations, etc.
// Cannot use constexpr here, smart_enum is incomplete at this point
static const smart_enum first, second;
};
constexpr smart_enum smart_enum::first = {}, smart_enum::second = {};
first 和 second 是否自动成为 inline 变量?还是我需要对它们进行资格认证?还是我无法将它们限定为内联并且需要稍后在某些源文件中提供定义?我一直对这种从 const 到 constexpr 的“重新定义”感到困惑,并希望能更清楚地了解这究竟意味着什么。
具体来说,我想知道const 声明与constexpr 定义之间的交互,以及它如何与static constexpr (Redefinitions of constexpr static data members are allowed now? (but not inline const)?) 的自动inline 相互作用
【问题讨论】:
-
“此外,constexpr 说明符意味着静态数据成员和函数的内联。” - 但是我会把那个 constexpr 放在我认为的类中。
-
@lorro 但你不能把它放在课堂上,这就是我困惑的根源。