[問題] function 如何傳入或回傳reference NULL

看板C_and_CPP作者 (呦厚厚)時間8年前 (2015/12/14 15:58), 8年前編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/1
很多人都會建議 多用 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

12/14 16:37, , 1F
寫 reference 就是 imply not null 請改用 pointer
12/14 16:37, 1F
而且我最近連 new object 都改用reference 接 好像有點沒必要....... ※ 編輯: yhn0tgb60 (218.35.163.53), 12/14/2015 17:13:25

12/14 17:31, , 2F
「多用 reference」正確,「只用 reference」肯定不對
12/14 17:31, 2F
文章代碼(AID): #1MRdQWs_ (C_and_CPP)