相关疑难解决方法(0)

由于定义顺序,"令人惊讶"的常量初始化

在阅读关于constexpr幻灯片时,介绍是关于"令人惊讶的动态初始化与consts".这个例子是

struct S {
    static const int c;
};
const int d = 10 * S::c;
const int S::c = 5;
Run Code Online (Sandbox Code Playgroud)

唉,音轨缺失了,音符也是如此,所以我只能猜到这里的含义.

是否正确d地"动态地"初始化,因为之前S::c定义了吗? d声明S::c是之前d可能是不够的,编译器需要完整的定义,对不对?

那就是说,我怀疑,在下面的例子中d 静态初始化?

struct S {
    static const int c;
};
const int S::c = 5;
const int d = 10 * S::c;  // now _after_ defn of S::c
Run Code Online (Sandbox Code Playgroud)

并采取蛋糕,在C++ 11,什么必须是constexpr完全静态初始化?S::c …

c++ initialization const constexpr c++11

13
推荐指数
1
解决办法
984
查看次数

标签 统计

c++ ×1

c++11 ×1

const ×1

constexpr ×1

initialization ×1