【发布时间】:2020-05-10 09:18:30
【问题描述】:
在我的书“C++ 编程语言”Bjarne Stroustrup 中,我读到了 const 成员 init 并看到了下一个代码(我更改了 var 名称和值):
class ConstMembers
{
public:
static const int a = 1; // ok
static int b = 2; // error: non const
const int c = 3; // error: no static
static const float d = 2.3; // error: not integer
};
但是当我在 Clion 2020.1 中使用下一个 cmake 设置运行此代码时
set(CMAKE_CXX_STANDARD 11)
第三种情况
const int c = 3; // error: no static
我没有收到错误消息。
是书上的错误还是c++11允许这样的初始化?
【问题讨论】:
-
你在读什么版本?我相信它是为 C++11 更新的第 4 版。
-
我读了翻译的书(俄文)。 2011 年写成“特别版”。