看板 C_and_CPP 關於我們 聯絡資訊
很多人都會建議 多用 reference 少用 point 可是當function 得回傳值或是 傳入值 是 NULL 時 要如何傳 NULL 的參數給 function 或是 回傳 NULL的reference? 雖然可以 int* aaa=NULL; int &bbb=*aaa; 但感覺很多此一舉 有更簡便的方式嗎? 感覺 reference 不適合處理 NULL的狀況? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 218.35.163.53 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1450079904.A.DBF.html ※ 編輯: yhn0tgb60 (218.35.163.53), 12/14/2015 16:18:10
nowar100: 寫 reference 就是 imply not null 請改用 pointer 12/14 16:37
而且我最近連 new object 都改用reference 接 好像有點沒必要....... ※ 編輯: yhn0tgb60 (218.35.163.53), 12/14/2015 17:13:25
uranusjr: 「多用 reference」正確,「只用 reference」肯定不對 12/14 17:31