→ Hazukashiine: 兩個不能同時被更改? 03/01 12:00
推 steve1012: 這句話要配例子看才有意思 03/01 12:21
→ steve1012: 假設你有兩個 變數 a,b 你想call一個 function 來改 a 03/01 12:22
→ steve1012: b的話 用 clla by reference可以直接在 function 裡 03/01 12:22
→ steve1012: 面改他們的值 03/01 12:22
→ steve1012: 但是你要是想用回傳值改的話 因為只回傳一個 int 你只 03/01 12:23
→ steve1012: 能改一個值 03/01 12:23
喔喔~我聽懂了 反正作者只是想表達用by value只能改a b其中一個,比如
a = func(a, b);
用by refernece則可以改一個以上
→ Lipraxde: 怎麼感覺你一直在計較些小地方啊 03/01 13:04
聽大家說這本書是聖經,所以我想要了解作者想表達的意思@@
※ 編輯: zzss2003 (60.248.26.157), 03/01/2018 13:15:26
→ MOONRAKER: 聖經就是大家都會說要看 但是通常不看 最好不用自己看 03/01 13:37
→ MOONRAKER: 再說一次你這樣讀書效率只會差不會好 03/01 13:37
→ MOONRAKER: 依照早期經驗 效果也很可疑 03/01 13:38
那M大您有什麼建議嗎~
※ 編輯: zzss2003 (60.248.26.157), 03/01/2018 13:48:02
推 rodion: 上面的解讀我看起來不太正確... 03/01 16:33
→ rodion: 我的解讀:即使C function是call-by-value(copy),某些情形 03/01 16:34
→ rodion: 依舊不適合在called function中更改argument值,作者舉例 03/01 16:35
→ rodion: array的ptr及size就屬於這類型argument 03/01 16:36
→ rodion: 不好意思沒看清楚原PO問的是7.2 03/01 16:39
→ rodion: 7.2我的解讀是作者想說的只是call-by-value的argument僅僅 03/01 16:40
→ rodion: 能在作為function return value的接收端被更改 (個人感覺 03/01 16:41
→ rodion: 這樣的說法不能說是錯,但有點沒必要,任何變數都能做為=的 03/01 16:43
→ rodion: lhs而被更改,不是嗎) 03/01 16:43
→ phishingphi: 太鑽牛角尖的念書方法了。單從這段話來說他只是再說 03/02 00:35
→ phishingphi: 個例子然後帶出 7.3 而已。 03/02 00:35
→ phishingphi: 如果想把 array 內的值打印出來,那怎麼會有人去改 03/02 00:36
→ phishingphi: caller 傳給你的資訊? 起點和多少個元素都是 caller 03/02 00:36
→ phishingphi: 跟你說的。 03/02 00:37
→ phishingphi: pass-by-value 的 signature 你宣告成 const 意義不 03/02 00:38
→ phishingphi: 大,我就複製一份給你這個函數去玩,你想怎麼改就怎 03/02 00:39
→ phishingphi: 麼改,只要想想你這個函數要幹嘛就好了。 03/02 00:39
→ phishingphi: 話說回來就是 7.3 是說把某些不該被改到的東西定成 03/02 00:41
→ phishingphi: const 然後 compiler 就能幫你檢查是不是手殘或眼拙 03/02 00:42
→ phishingphi: 而不小心改到一些不該改的值。 03/02 00:42
→ phishingphi: 小結:黃色框起來的字我認為只是為了帶出 7.3,但是 03/02 00:46
→ phishingphi: 函數 pass-by-value parameter 的通常不需要帶 const 03/02 00:49
→ phishingphi: pass-by-reference 則要看情況。 03/02 00:50
→ phishingphi: (小結後面的但是好像應該擺到上面...和書的字面內容 03/02 00:51
→ phishingphi: 無關,純屬個人看法)。 03/02 00:51
推 steve1012: 原 po哪裡寫了 const 嗎 怎麼沒看到 03/02 01:28
推 adrianshum: 理解成這樣就好了:一般情況下function 只能return 03/02 02:51
→ adrianshum: 單一數值,所以caller 只能用單一變數接收,意味一 03/02 02:51
→ adrianshum: 次function call 只能影響到一個變數。要一次影響多 03/02 02:51
→ adrianshum: 個變數就請用pass by ref 03/02 02:51
→ phishingphi: 回網友 steve1012:圖片7.3有類似的含義,只是順著原 03/02 18:37
→ phishingphi: po的例子探討1. pass by value 的argument 要不要加 03/02 18:37
→ phishingphi: const 2. pass by value 因為是 copy 所以函數要怎麼 03/02 18:39
→ phishingphi: 改就怎麼改,我認為不用加const。都是7.3延伸。原po 03/02 18:39
→ phishingphi: 用黃色框起來的字只是連結7.3的轉折語而已。 03/02 18:39