Re: [問題] class中cast operator

看板C_and_CPP (C/C++)作者 (人生的轉捩點)時間16年前 (2010/06/28 02:47), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
Try it. #include <iostream> using namespace std; class intwrapaer { public: intwrapaer(int x):val(x){} operator int (); void print(); int operator ++(int); private: int val; }; int intwrapaer::operator ++ (int) { return val++; } intwrapaer::operator int() { return val; } int main() { intwrapaer ivalue(3.7); cout << ivalue << endl; int d = ivalue++; cout << d << endl; cout << ivalue << endl; system("PAUSE"); return 0; } 補充說明: -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.231.68.43 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 219.71.218.214
文章代碼(AID): #1C9vpCVp (C_and_CPP)
文章代碼(AID): #1C9vpCVp (C_and_CPP)