作者LPH66 (凉宫春日症候群)
看板Programming
标题Re: c++的指标用在引数上
时间Sun Nov 5 10:08:54 2006
※ 引述《[email protected] ( )》之铭言:
: ※ 引述《[email protected] (三亿两千万大散户)》之铭言:
: > 以我的观念
: > pointer是比较属於C的东西
: > reference才是C++的东西
: > 我觉得两者效率应该一样
: > 因为都没有复制资料的动作
: > 以compiler来看
: > pointer会比reference多占一块记忆体空间用来储存位址
: > 所以传pointer时你可以拿该pointer再指到别的地方
: > 但是传reference时你不能改变reference到的地方
: 用 reference 效率应该会比较好吧。(其实只有好一丁点而已。)
: 因为使用 pointer 传递,会复制「位址」这个数值,
: 然後再利用「位址」这个数值做事。例如 pointer->function();
如果只是C++的话
我记得有些compiler底层是用传指标来实作pass by reference的...
(也许记忆有误 欢迎指正 @@)
--
'Oh, Harry, dont't you
see?' Hermione breathed. 'If she could have done
one thing to make
absolutely sure that every single person in this school
will read your interview, it was
banning it!'
---'Harry Potter and the order of the phoenix', P513
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 192.192.197.112