using namespace std;
class Complex
{
public:
Complex(int a, int b)
{
this->a = a;
this->b = b;
}
friend Complex & operator++(Complex &c);
friend const Complex operator++(Complex &c1, int);
Complex &operator++()
{
this->a++;
this->b++;
return *this;
}
const Complex operator++(int)//亚元
{
Complex temp(this->a, this->b);
this->a++;
this->b++;
return temp;
}
private:
int a;//实数
int b;//虚数
};
//重载的是前++运算符
Complex & operator++(Complex &c)
{
c.a++;
c.b++;
return c;
}
//重载的是后++运算符
const Complex operator++(Complex &c1, int)
{
Complex temp(c1.a, c1.b);
c1.a++;
c1.b++;
return temp;
}
int main(void)
{
Complex c1(1, 2);
//++++c1;
c1++;
//++++c1;
return 0;
}
重载++
最新推荐文章于 2024-04-18 01:04:31 发布
博客围绕运算符++重载展开,但具体内容缺失。++重载在编程中是重要概念,可改变运算符原有行为,以适应特定需求,在面向对象编程等领域有广泛应用。
6718

被折叠的 条评论
为什么被折叠?



