小编cod*_*dex的帖子

重载Postfix和前缀运算符

我想知道这是否是重载post和pre increment运算符的正确代码.

如何在main()中调用这些运算符.

class fix{
int x;
int y;
public:fix(int = 0, int = 0);
   fix operator++(){//prefix increment
       fix a;
       ++a.x;
       ++a.y; 
       return a;
}
   fix operator++(int){ //post fix increment
       fix c;
       c.x = x;
       c.y = y;
       x++; y++;
       return c;
   }
};
Run Code Online (Sandbox Code Playgroud)

c++ class operator-overloading

-3
推荐指数
1
解决办法
486
查看次数

标签 统计

c++ ×1

class ×1

operator-overloading ×1