簡體   English   中英

重載后綴增量運算符

[英]Overloading postfix increment operator

我正在嘗試將后綴增量運算符作為類的成員函數重載,該類將大量數字存儲為一個int數組。 但是它總是以0的形式返回。關於此無效的任何提示?

這是一個作業問題,所以我想提供更多技巧而不是簡單的代碼。 謝謝。

成員數據如下:

largeInt = new int[maxSize];
int maxSize, currentSize;

其中currentSize是一個跟蹤變量,用於跟蹤當前數組的大小。

我的代碼是:

Load函數將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;
}   

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM