Re: 陳銘憲計程考古題code 4

看板NTUEE107HW作者 (溪山清靜且停停)時間20年前 (2004/01/11 18:36), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/3 (看更多)
※ 引述《OLLEJ (今生有憾此恨無悔)》之銘言: : ※ 引述《wanderer (靜心)》之銘言: : #include <iostream.h> : #include <stdlib.h> : class MyInt{ : friend ostream& operator <<(ostream& os, const MyInt& x); : private: : int data; : public: : MyInt(int value=0){ : data = value; : cout<<"MyInt:"<<data<<endl; : } : ~MyInt(){ : cout<<"~MyInt:"<<data<<endl; : } : MyInt(const MyInt& b){ : data = b.data-1; : cout<<"MyInt(const MyInt&)"<<data<<endl; : } : MyInt& operator=(MyInt& b){ : int temp = data; : data=b.data; b.data = temp; : return b; : } : operator int(){return data+1;} : }; : ostream& operator<<(ostream& os, const MyInt& x}{ ^ 這邊我打錯了.. : return os<<x.data-1; : } : int main() : { : MyInt a(17),b=10,c=a,d; : (b=a)=(d=c); : cout<<a<<","<<(int)b<<","<<(int)c<<","<<d<<endl; : return 0; : } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.224.140.85
文章代碼(AID): #100ISXHm (NTUEE107HW)
文章代碼(AID): #100ISXHm (NTUEE107HW)