作者yhn0tgb60 (呦厚厚)
看板C_and_CPP
标题[问题] function 如何传入或回传reference NULL
时间Mon Dec 14 15:58:22 2015
很多人都会建议 多用 reference 少用 point
可是当function 得回传值或是 传入值 是 NULL 时
要如何传 NULL 的参数给 function 或是 回传 NULL的reference?
虽然可以 int* aaa=NULL;
int &bbb=*aaa;
但感觉很多此一举 有更简便的方式吗?
感觉 reference 不适合处理 NULL的状况?
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 218.35.163.53
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1450079904.A.DBF.html
※ 编辑: yhn0tgb60 (218.35.163.53), 12/14/2015 16:18:10
1F:推 nowar100: 写 reference 就是 imply not null 请改用 pointer 12/14 16:37
而且我最近连 new object 都改用reference 接
好像有点没必要.......
※ 编辑: yhn0tgb60 (218.35.163.53), 12/14/2015 17:13:25
2F:→ uranusjr: 「多用 reference」正确,「只用 reference」肯定不对 12/14 17:31