Re: [問題] friend ostream

看板EE_DSnP作者 (Ric)時間15年前 (2009/04/13 13:11), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《dxi (D差耶)》之銘言: : 請教教授和各位同學: : // friend functions : friend ostream& operator << (ostream&, const ModNum&); // TODO : 我知道friend功能是可以讓其他地方使用特定函式。 friend 的用處是可以讓被 friend 的 class/function 可以直接存取授予 friendship 的 class 的 private data members and member functions : 然而在上述式子中,卻苦思不得起解。有以下問題: : A.查詢google得知osteam& operator與資料共享有關。 google 要慎用... 我不知道 osteam& operator與資料共享有什麼關係... : 然而TODO中的ostream的物件該是什麼呢?_varMap嗎? friend ostream& operator << (ostream& os, const ModNum&); -------- ----------- return os 傳入 cout => os 不如看一下螞蟻書, 就有 friend ostream& operator << (ostream&, ...) 的例子了 : B.在ModNum的class中為什麼還要將資料共享/複製給ModNum的物件呢? : 若是我理解錯誤,那本函式又該是什麼意思呢? 不是很了解, 請問你是指哪一段 code? : 先謝謝大家的回答了。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.21.241

04/17 02:26, , 1F
問題解決了 謝謝教授
04/17 02:26, 1F
文章代碼(AID): #19uicNE6 (EE_DSnP)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
文章代碼(AID): #19uicNE6 (EE_DSnP)