我在试着理解这段代码。我只想弄清楚为什么d和e是int*和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)发布于 2018-01-04 12:39:52
&i的意思是“取i__的地址”。因为i是int,所以&i的类型是int*。由于d的存在,int*的类型被推导为自动类型推理规则。
同样的推理也适用于ci。唯一的区别是const限定符。
https://stackoverflow.com/questions/48095510
复制相似问题