C++ 中的复合类型、const 和 auto

Compound types, const and auto in C++

我正在尝试理解这段代码。我一直想弄清楚为什么 deint*const int*。我需要一些帮助。

const int ci = i, &cr = ci;
auto b = ci; // b is an int (top-level const in ci is dropped)
auto c = cr; // c is an int (cr is an alias for ci whose const is top-level)
auto d = &i; // d is an int*(& of an int object is int*)
auto e = &ci; // e is const int*(& of a const object is low-level const)

&i 表示 "take the address of i"。由于 iint,因此 &i 的类型是 int*。由于automatic type deduction rules.

d的类型推导出为int*

同样的推理也适用于 ci。唯一的区别是 const 限定符。