看板 NTUEE107HW 關於我們 聯絡資訊
※ 引述《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