Re: [問題]關於 overload的問題
※ 引述《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
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章