作者beckon (長不大的小孩)
看板C_and_CPP
標題[問題] operator<< (輸出建構子不知道怎樣輸出)
時間Mon May 18 22:57:56 2009
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)
1F:推 legnaleurc:簽名就不對了 05/18 23:01
2F:→ beckon:???? 不懂大大的意思 05/18 23:05
3F:推 j87b0003:我改成:a &f 裡面用 f.bo 就可以了。。。。 05/18 23:40
十分感謝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)