65,211
社区成员
发帖
与我相关
我的任务
分享
class Point
{
int x,y;
public:
void set(int a,int b);
Point operator+(Point& d);
friend ostream& operator <<(ostream&o,Point&d);
};
inline ostream& operator <<(ostream&o,Point&d)
{
return o <<'(' <<d.x <<',' <<d.y <<')' <<endl;
}
void Point::set(int a,int b){x=a,y=b;}
Point Point::operator +(Point&d)
{
Point s;
s.set(x+d.x,y+d.y);
return s;
}
int main()
{
Point s,t;
s.set(2,5);
t.set(3,1);
cout <<s+t;
system("pause");
}
class Point
{
int x,y;
public:
void set(int a,int b);
Point operator+(Point& d);
friend ostream& operator <<(ostream&o,Point&d);
};
inline ostream& operator <<(ostream&o,Point&d)
{
return o <<'(' <<d.x <<',' <<d.y <<')' <<endl;
}
void Point::set(int a,int b){x=a,y=b;}
Point Point::operator +(Point&d)
{
Point s;
s.set(x+d.x,y+d.y);
return s;
}
int main()
{
Point s,t;
s.set(2,5);
t.set(3,1);
Point tmp = s+t;
cout <<tmp;
}