看板 NTUEE107HW 關於我們 聯絡資訊
#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.216.80.233