#include<iostream>
using namespace std;
class Point
{
public:
int x;
int y;
};
Point operator+ (Point p1, Point p2)
{
Point temp;
temp.x = p1.x + p2.x;
temp.y = p1.y + p2.y;
return temp;
}
void test()
{
Point p1;
p1.x = 10;
p1.y = 10;
Point p2;
p2.x = 20;
p2.y = 20;
Point p3 = p1 + p2;
cout<<"p3="<<"("<<p3.x<<","<<p3.y<<")"<<endl;
}
int main()
{
test();
return 0;
}
通过重载运算符实现点对象的相加
最新推荐文章于 2024-09-26 12:00:11 发布