#include<iostream>
using namespace std;
class point11
{
int x;int y;
public:
point11()
{
x=0;y=0;
}
point11(int ix,int iy)
{
x=ix;
y=iy;
}
friend point11 operator +(const point11& pt1,const point11& pt2);//在vc6下存在bug,报错fatal error C1001: INTERNAL COMPILER ERROR,在vc2005下能通过测试
int getx()
{
return x;
}
int gety()
{
return y;
}
};
point11 operator+(const point11& pt1,const point11& pt2)
{
point11 repoint;
repoint.x=pt1.x+pt2.x;
repoint.y=pt1.y+pt2.y;
return repoint;
}
int main()
{
point11 a(20,30);
point11 b(10,20);
point11 c;
c=a+b;
cout<<c.getx()<<","<<c.gety()<<endl;
}
友元实现point+point
最新推荐文章于 2022-04-17 18:43:59 发布