Re: [問題]關於 overload的問題

看板C_and_CPP (C/C++)作者 (CA)時間16年前 (2009/05/10 13:51), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《conan77420 (小馬非馬)》之銘言: : 1.是用dve。為什麼在class中的int w,h,d;前如果加上private會編譯不過? : 不是在不同class的時候private才會不能存取嗎?〈好吧我承認這跟overload沒關 /_\〉 It works on my machine. 應該是你有其他語法打錯 : 2.如果把class中的operator+(const box &b)拉出來 : 寫成:box::box operator+(const box &b) : { : box temp; : temp.w=w+b.w; : temp.h=h+b.h; : temp.d=d+b.d; : return temp; : } : 為什麼編譯會不過呢? 語法錯誤 box box::operator +( const box & b ) { // ... } : 3.如果要做cout的overload,副程式的類別是要用ofstream嗎? : 就是寫成像這樣:ofstream operator<<(ofstream &out,box &b) : 不過編譯沒過,請問該怎麼修正? : 謝謝! friend ostream & operator <<( ostream & out, const box & b ) { // ... return out } -- 自High筆記(半荒廢) http://legnaleurc.blogspot.com/ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.146.194.91

05/10 16:02, , 1F
三題全部成功,大大您太強了!!!
05/10 16:02, 1F
文章代碼(AID): #1A1cjqYH (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1A1cjqYH (C_and_CPP)