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

问题描述 投票:3回答:1

我试图理解这段代码。我一直在弄清楚为什么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)
c++ c++11 const auto
1个回答
5
投票

&i的意思是“取i的地址”。由于iint&i的类型是int*。由于dint*的类型被推断为automatic type deduction rules

同样的推理可以适用于ci。唯一的区别是const资格赛。

© www.soinside.com 2019 - 2024. All rights reserved.