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

时间:2018-01-04 12:37:40

标签: c++ c++11 const auto

我试图理解这段代码。我一直在弄清楚为什么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)

1 个答案:

答案 0 :(得分:5)

UIImagePickerControllerSourceTypeCamera表示“取- (void)channel:(SBDBaseChannel *)sender didReceiveMessage:(SBDBaseMessage *)message 的地址。由于&ii,因此i的类型为int。由于automatic type deduction rules&i的类型推断为int*

同样的推理可以适用于d。唯一的区别是int*限定符。