C++定义Point类,有成员变量X、Y,为其定义友元函数实现重载+。

很急啊
2024-12-02 05:22:19
推荐回答(1个)
回答1:

class Point
{
private:
int x,y;
public:
Point(int a=0,int b=0):x(a),y(b){}
friend Point operator + (Point const & a,Point const & b);
};
Point operator + (Point const & a,Point const & b)
{
return Point(a.x+b.x,a.y+b.y);
}