Re: [問題] 參數傳指標還是傳reference
看板C_and_CPP (C/C++)作者uranusjr (←這人是超級笨蛋)時間13年前 (2012/08/25 08:13)推噓1(1推 0噓 0→)留言1則, 1人參與討論串2/2 (看更多)
※ 引述《sorryChen (陳揚和)》之銘言:
→
08/23 16:34,
08/23 16:34
→
08/23 17:19,
08/23 17:19
→
08/23 17:20,
08/23 17:20
→
08/23 17:21,
08/23 17:21
→
08/23 17:22,
08/23 17:22
推
08/23 17:27,
08/23 17:27
→
08/23 17:29,
08/23 17:29
→
08/23 18:02,
08/23 18:02
我的習慣也是這樣(從 Qt Style 偷來的)
http://doc.qt.nokia.com/qq/qq13-apis.html#pointersorreferences
Most C++ books recommend references whenever possible, according to the
general perception that references are "safer and nicer" than pointers.
In contrast, at Trolltech, we tend to prefer pointers because they make
the user code more readable. Compare:
color.getHsv(&h, &s, &v);
color.getHsv(h, s, v);
Only the first line makes it clear that there's a high probability that h,
s, and v will be modified by the function call.
我自己是只在傳入不需修改內容值(沒有副作用)
但傳值又比較浪費資源(例如必須傳一整個物件進去)時
才會使用參考作為函式傳入值
--
╱ ̄ ̄ ̄╲
▏◢█◣ ▏
︻█︻█ ▏ 成龍表示: 是喔...
′/ ‵ ▏
╰╯ █╱
ψQSWEET ◥︶█◤
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.243.36.234
推
08/26 02:29, , 1F
08/26 02:29, 1F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章