我试图理解这段代码。我一直在弄清楚为什么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)
&i
的意思是“取i
的地址”。由于i
是int
,&i
的类型是int*
。由于d
,int*
的类型被推断为automatic type deduction rules。
同样的推理可以适用于ci
。唯一的区别是const
资格赛。