C++,问题求大神解答!下面的代码错在哪里了?求改正啊!
#include<iostream>usingnamespacestd;classPoint{intx,y;public:Point(inta=0,intb=0):x(a...
#include<iostream>
using namespace std;
class Point
{
int x,y;
public:
Point(int a=0,int b=0):x(a),y(b){}
int Get_X(){return x;}
int Get_Y(){return y;}
Point operator+(Point&p1);
Point operator-(Point&p2);
friend ostream &operator<<(ostream&p,const Point &A);
};
ostream& operator<<(ostream&p,const Point&A)
{
p<<A.x<<" "<<A.y;
return p;
}
Point Point::operator +(Point&p1,Point&p)
{
return Point(p.x+p1.Get_X(),p.y+p1.Get_Y());
}
Point Point::operator -(Point&p2)
{
return Point(x-p2.x,y-p2.y);
}
int main()
{
Point A(2,5),B(4,6),C,D;
C=A+B;
D=A-B;
cout<<A<<endl;
cout<<"A+B="<<C.Get_X()<<" "<<C.Get_Y()<<endl;
cout<<"A-B="<<D.Get_X()<<" "<<D.Get_Y()<<endl;
return 0;
} 展开
using namespace std;
class Point
{
int x,y;
public:
Point(int a=0,int b=0):x(a),y(b){}
int Get_X(){return x;}
int Get_Y(){return y;}
Point operator+(Point&p1);
Point operator-(Point&p2);
friend ostream &operator<<(ostream&p,const Point &A);
};
ostream& operator<<(ostream&p,const Point&A)
{
p<<A.x<<" "<<A.y;
return p;
}
Point Point::operator +(Point&p1,Point&p)
{
return Point(p.x+p1.Get_X(),p.y+p1.Get_Y());
}
Point Point::operator -(Point&p2)
{
return Point(x-p2.x,y-p2.y);
}
int main()
{
Point A(2,5),B(4,6),C,D;
C=A+B;
D=A-B;
cout<<A<<endl;
cout<<"A+B="<<C.Get_X()<<" "<<C.Get_Y()<<endl;
cout<<"A-B="<<D.Get_X()<<" "<<D.Get_Y()<<endl;
return 0;
} 展开
2个回答
展开全部
#include<iostream>
using namespace std;
class Point;
extern ostream &operator<<(ostream&p,Point &A);
class Point
{
int x,y;
public:
Point(int a=0,int b=0):x(a),y(b){}
int Get_X(){return x;}
int Get_Y(){return y;}
Point operator+(Point&p1);
Point operator-(Point&p2);
friend ostream &operator<<(ostream&p,Point &A);
};
ostream& operator<<(ostream&p,Point&A)
{
p<<A.Get_X()<<" "<<A.Get_Y();
return p;
}
Point Point::operator +(Point&p1)
{
return Point(this->Get_X()+p1.Get_X(),this->Get_Y()+p1.Get_Y());
}
Point Point::operator -(Point&p2)
{
return Point(x-p2.x,y-p2.y);
}
int main()
{
Point A(2,5),B(4,6),C,D;
C=A+B;
D=A-B;
cout<<A<<endl;
cout<<"A+B="<<C.Get_X()<<" "<<C.Get_Y()<<endl;
cout<<"A-B="<<D.Get_X()<<" "<<D.Get_Y()<<endl;
return 0;
}
更多追问追答
追问
为什么我用的VC++6还是无法编译通过...........我....
追答
你复制我的代码吗?你先测试hello world可以编译吗?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询