Re: c++的指標用在引數上

看板Programming作者 (涼宮春日症候群)時間17年前 (2006/11/05 10:08), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串4/5 (看更多)
※ 引述《previewslave@kkcity.com.tw ( )》之銘言: : ※ 引述《meltice.bbs@ptt.cc (三億兩千萬大散戶)》之銘言: : > 以我的觀念 : > 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
文章代碼(AID): #15JKU3j0 (Programming)
文章代碼(AID): #15JKU3j0 (Programming)