[問題] operator<< (輸出建構子不知道怎樣輸出)

看板C_and_CPP (C/C++)作者 (長不大的小孩)時間16年前 (2009/05/18 22:57), 編輯推噓2(201)
留言3則, 3人參與, 最新討論串1/1
class a { friend ostream &operator<<(ostream out,const a *f) { out<<f->bo<<","<<f->co<<endl; return out; } public: a(int b,int c) { bo=b; co=c; } private: int bo,co; }; int main(int argc, char *argv[]) { a t(1,2); cout<<t; ????????????????請問我要如何才能將t印出來為1,2 system("PAUSE"); return EXIT_SUCCESS; } 忙煩大大們幫忙一下 我這個問題卡很久了 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 125.224.74.39 ※ 編輯: beckon 來自: 125.224.74.39 (05/18 22:59)

05/18 23:01, , 1F
簽名就不對了
05/18 23:01, 1F

05/18 23:05, , 2F
???? 不懂大大的意思
05/18 23:05, 2F

05/18 23:40, , 3F
我改成:a &f 裡面用 f.bo 就可以了。。。。
05/18 23:40, 3F
十分感謝J大的幫忙 我將程式改成 friend ostream &operator<<(ostream &out,const a &f) { out<<f.bo<<" "<<f.co<<endl; return out; } 終於可以輸出 ※ 編輯: beckon 來自: 125.224.74.39 (05/18 23:59)
文章代碼(AID): #1A4NTrl2 (C_and_CPP)
文章代碼(AID): #1A4NTrl2 (C_and_CPP)