繁体   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