// increment_and_decrement1.cpp
class Point
{
public:
// Declare prefix and postfix increment operators.
Point& operator++(); // Prefix increment operator.
Point operator++(int); // Postfix increment operator.
// Declare prefix and postfix decrement operators.
Point& operator--(); // Prefix decrement operator.
Point operator--(int); // Postfix decrement operator.
// Define default constructor.
Point() { _x = _y = 0; }
// Define accessor functions.
int x() { return _x; }
int y() { return _y; }
private:
int _x, _y;
};
// Define prefix increment operator.
Point& Point::operator++()
{
_x++;
_y++;
return *this;
}
// Define postfix increment operator.
Point Point::operator++(int)
{
Point temp = *this;
++*this;
return temp;
}
// Define prefix decrement operator.
Point& Point::operator--()
{
_x--;
_y--;
return *this;
}
// Define postfix decrement operator.
Point Point::operator--(int)
{
Point temp = *this;
--*this;
return temp;
}
int main()
{
}
friend Point& operator++( Point& ) // Prefix increment friend Point& operator++( Point&, int ) // Postfix increment friend Point& operator--( Point& ) // Prefix decrement friend Point& operator--( Point&, int ) // Postfix decrement
// increment_and_decrement2.cpp
class Int
{
public:
Int &operator++( int n );
private:
int _i;
};
Int& Int::operator++( int n )
{
if( n != 0 ) // Handle case where an argument is passed.
_i += n;
else
_i++; // Handle case where no argument is passed.
return *this;
}
int main()
{
Int i;
i.operator++( 25 ); // Increment by 25.
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有