【发布时间】:2013-10-24 19:49:57
【问题描述】:
类定义中初始化的静态整型数据成员可以声明const或constexpr,但类定义中初始化的非整型静态数据成员必须是constexpr:
class MyClass {
static const int w = 5; // okay
static constexpr int x = 5; // okay
static const float y = 1.5; // error!
static constexpr float z = 1.5; // okay
};
有人知道为什么不允许声明 y 吗?使其非法的标准部分是 9.4.2/3,但为什么它是非法的?
【问题讨论】:
-
历史、遗产、演变、传统?
-
你看过this answer吗?
-
@GabrielL.:您链接到的答案似乎是涉及 C++98 的讨论,而不是 C++11。
标签: c++ c++11 static-members constexpr