Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C+中的复合类型、常量和自动+;_C++_C++11_Constants_Auto - Fatal编程技术网

C++ C+中的复合类型、常量和自动+;

C++ C+中的复合类型、常量和自动+;,c++,c++11,constants,auto,C++,C++11,Constants,Auto,我正在努力理解这段代码。我一直在想为什么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 in

我正在努力理解这段代码。我一直在想为什么
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*


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

非常感谢,这很有意义@BiancaStan如果这个答案适合你,请点击答案分数周围的复选标记。这总比说谢谢好;)请提供一份报告。代码中缺少
i
的定义。