簡體   English   中英

C ++中的復合類型,const和auto

[英]Compound types, const and auto in C++

我試圖理解這段代碼。 我一直在弄清楚為什么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)

&i意思是“拿i的地址” 因為i是一個int ,所以&i的類型是int* 由於自動類型推導規則d的類型被推導為int*

同樣的推理可以應用於ci 唯一的區別是const限定符。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM