2010-11-09 93 views
1

我想重載後綴增量運算符作爲一個類存儲大數字作爲一個整數的數組的成員函數。但它一直返回爲0.任何提示爲什麼這不起作用?重載後綴增量運算符

這是一個家庭作業問題,所以我想要比直接代碼更多的提示。謝謝。

成員的數據是這樣的:

​​

哪裏currentSize是用於跟蹤的陣列目前有多大是一個跟蹤變量。

而且我的代碼是:

負載的功能在陣列中把一個int在第一地點與其他人在移動的一切。

/* postfix*/ 
NewInt& NewInt::operator++(int nothing) 
{ 
    int count = 1; 
    largeInt[currentSize - count] += 1; 
    while(largeInt[currentSize - count] > 9) 
    { 
      if(currentSize - count - 1 < 0) 
      { 
        firstVar = true; 
        Load(1); 
      } 
      else  
        largeInt[currentSize - count - 1] += 1; 

      count++;    
    } 

    return *this; 
} 
+0

你顯示LargeInt,但實際的代碼使用'數字'。是數字引用LargeInt – Chubsdad 2010-11-09 03:46:28

+2

不命名operator ++的參數;這是一個最佳實踐 – Chubsdad 2010-11-09 03:48:22

+0

是的,我把它改成了largeInt,它在我的程序中是正確的,只是有點累,從測試程序複製和粘貼。固定。 – dubyaa 2010-11-09 03:51:25

回答

3

您的評論與您的​​代碼不符。 operator++(int)是後綴增量,operator++()是前綴。

+0

糟糕,以及我需要無論如何都要做他們倆。我將它編輯爲postfix – dubyaa 2010-11-09 03:40:41

+0

ok,所以postfix的確適用於這種變化。 – dubyaa 2010-11-09 03:54:15

+0

至少部分。做,99 ++給出110. – dubyaa 2010-11-09 03:55:58