#include <iostream.h>
class Point //复数类
{
private:
int x,y;
public:
Point(int i=0, int j=0)//构造函数
{
x=i;
y=j;
}
void Show() //显示点值,格式:(x,y)
{
cout<<"("<<x<<","<<y<<")"<<endl;
}
Point operator ++(); //声明前置自增运算符“++”重载函数
Point operator ++(int); //声明后置自增运算符“++”重载函数(傻瓜式定义)
};
Point Point::operator ++() //定义前置自增运算符“++”重载函数
{
++x;
++y;
return *this;
}
Point Point::operator ++(int) //定义后置自增运算符“++”重载函数
{
Point ptold(x,y);
ptold.x=x++;
ptold.y=y++;
return ptold;
}
int main()
{
Point p1(20,40),p2;
p1.Show();
p2=p1++;
p1.Show();
p2.Show();
p2=++p1;
p1.Show();
p2.Show();
return 0;
}
class Point //复数类
{
private:
int x,y;
public:
Point(int i=0, int j=0)//构造函数
{
x=i;
y=j;
}
void Show() //显示点值,格式:(x,y)
{
cout<<"("<<x<<","<<y<<")"<<endl;
}
Point operator ++(); //声明前置自增运算符“++”重载函数
Point operator ++(int); //声明后置自增运算符“++”重载函数(傻瓜式定义)
};
Point Point::operator ++() //定义前置自增运算符“++”重载函数
{
++x;
++y;
return *this;
}
Point Point::operator ++(int) //定义后置自增运算符“++”重载函数
{
Point ptold(x,y);
ptold.x=x++;
ptold.y=y++;
return ptold;
}
int main()
{
Point p1(20,40),p2;
p1.Show();
p2=p1++;
p1.Show();
p2.Show();
p2=++p1;
p1.Show();
p2.Show();
return 0;
}
1080

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



