看板 C_and_CPP 關於我們 聯絡資訊
我是C++的新手,最近讀到 reference to pointer 時, 發現他的宣告是 : int *&a; 為什麼不是 : int &*a; 呢? 簡單查了一下過去的文章 好像沒有看到有討論過,是我哪裡理解錯誤了嗎? 還是這只是純粹的規定? 謝謝! -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.109.103.227 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1441940162.A.732.html
BlazarArc: Type &varable; 變數variable是型別為type的變數的ref 09/11 11:18
BlazarArc: 你想想怎麼帶入Type與variable的宣告 09/11 11:19
bibo9901: right-left rule 09/11 11:20
BlazarArc: 所以我pointer都寫 int* a 不喜歡寫 int *a 09/11 11:20
FlyBrother: 謝謝以上兩位,我查了right-left rule之後了解了!! 09/11 11:32
fatrabitree: C++這點很奇怪,因為又可以寫int a,*b; 09/11 14:15
BlazarArc: 所以不要那樣寫 很不方便(?) 09/11 14:27
bibo9901: 對... 如果你寫 int* a, b; 會讓人誤以為 b 也是 int* 09/11 15:32
BlazarArc: 一行不要宣告兩個變數就好啦 09/11 16:17
azureblaze: typedef int *intptr; intptr a,b; intptr &c; 09/11 18:10
azureblaze: 人腦parser很爛的不要欺負他 09/11 18:11
kwpn: 由右往左讀呀 09/12 17:49