看板 C_and_CPP 關於我們 聯絡資訊
※ 引述《hnaxiorll (fairyland)》之銘言: : 因為最近c++作業,遇到階乘的問題 : 如果我想 opertor overloading ! 來處理不知道這樣可以嗎?? : 如果可以那該如何下手呢? : 感謝各位幫忙解答 m(─_─)m 又到了寫低能code的時間~ 以下VS2008限定, 2005或更早的可能不行 gcc的-fextended-identifiers還是個半成品(敲碗) #define ! + 階乘() /* 這是全形的"!" 不是"!" */ struct 階乘{}; int operator+(int x, const 階乘& y) { int j = 1; for(int i=1; i<=x; i++) j *= i; return j; } int main() { cout << 5! << endl; int a = 6; cout << a ! << endl; // a和!中間要有空格 不然會被當成一個identifier return 0; } -- -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.116.156.17 ※ 編輯: Fenikso 來自: 122.116.156.17 (05/14 16:24)
ledia:haha 05/14 16:32
adrianshum:服了你! :D 05/14 16:33
littleshan:叔叔有練過 好孩子請勿任意模仿 XD 05/14 16:40
legendmtg:XDDDD 05/14 16:55
VictorTom:XDDDD 05/14 17:14
windincloud:DDD <= 沒照顧長id 05/14 17:20
chrisdar: DDD 大推阿 05/14 18:08
adrianshum:XDDD 05/14 18:42
Ebergies: XDDDD 北爛到爆 05/14 20:23
WPC001: XDDDD 一定要推的阿... 超級北爛 05/14 20:29
hnaxiorll:囧 05/15 09:41
yoco315:ㄎㄎ 05/18 01:15