1个回答
展开全部
不知道你要派生什么类,写了基本符合你要求吧
#include <iostream>
using namespace std;
class point
{
public:
point() : m_x(0), m_y(0){}
point(int x, int y) : m_x(x), m_y(y){}
~point(){}
friend point operator +(const point& p1, const point& p2);
point& operator =(const point& p1);
protected:
double m_x;
double m_y;
};
point operator +(const point& p1, const point& p2)
{
point p3;
p3.m_x = p1.m_x + p2.m_x;
p3.m_y = p1.m_y + p2.m_y;
return p3;
}
point& point::operator =(const point& p1)
{
this->m_x = p1.m_x;
this->m_y = p1.m_y;
return *this;
}
int main()
{
point p1(1, 2), p2(4, 5);
point p3;
p3 = p1 + p2;
return 0;
}
#include <iostream>
using namespace std;
class point
{
public:
point() : m_x(0), m_y(0){}
point(int x, int y) : m_x(x), m_y(y){}
~point(){}
friend point operator +(const point& p1, const point& p2);
point& operator =(const point& p1);
protected:
double m_x;
double m_y;
};
point operator +(const point& p1, const point& p2)
{
point p3;
p3.m_x = p1.m_x + p2.m_x;
p3.m_y = p1.m_y + p2.m_y;
return p3;
}
point& point::operator =(const point& p1)
{
this->m_x = p1.m_x;
this->m_y = p1.m_y;
return *this;
}
int main()
{
point p1(1, 2), p2(4, 5);
point p3;
p3 = p1 + p2;
return 0;
}
追问
亲,有QQ没,能不能再帮我看几个程序,528213665
追答
少上Q,hi上回答吧
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询