组合类的设计,编译器一直报错,就是没有告诉我错在哪行?
设计一个line(线段类),子类有Piont类。
#include<iostream>编译器 类 设计
#include<cmath>
using namespace std;
class Point{
private:
int x,y;
public:
Point()
{
x=0;
y=0;
}
Point(int x,int y)
{
this->x=x;
this->y=y;
}
Point(Point &p)
{
x=p.x;
y=p.y;
}
int GetX();
int GetY();
void SetX();
void SetY();
};
class Line{
private:
Point p1,p2;
float len;
public:
Line():p1(1,1),p2(2,2)
{
len=sqrt( ( p1.GetX()-p2.GetX())*(p1.GetX()-p2.GetX())+(p1.GetY()-p1.GetY())*(p1.GetY()-p1.GetY()) );
}
Line(Line &l):p1(l.p1),p2(l.p2)
{
cout<<"调用构造函数"<<endl;
}
Line(Point xp1,Point xp2):p1(xp1),p2(xp2)
{
len=sqrt( ( p1.GetX()-p2.GetX())*(p1.GetX()-p2.GetX())+(p1.GetY()-p1.GetY())*(p1.GetY()-p1.GetY()) );
}
float GetLen()
{
return len;
}
Point GetPoint1()
{
return p1;
}
Point GetPoint2()
{
return p2;
}
};
int main()
{
Point p1(10,10);
Point p2(1,1);
Line l1();
Line l2(p1,p2);
return 0;
}
#include<iostream>
#include<cmath>
using namespace std;
class Point{
private:
int x,y;
public:
Point()
{
x=0;
y=0;
}
Point(int x,int y)
{
this->x=x;
this->y=y;
}
Point(Point &p)
{
x=p.x;
y=p.y;
}
int GetX();
int GetY();
void SetX();
void SetY();
};
int Point::GetX(){return x;}
int Point::GetY(){return y;}
class Line{
private:
Point p1,p2;
float len;
public:
Line():p1(1,1),p2(2,2)
{
len=sqrt( (double)( p1.GetX()-p2.GetX())*(p1.GetX()-p2.GetX())+(p1.GetY()-p1.GetY())*(p1.GetY()-p1.GetY()) );
}
Line(Line &l):p1(l.p1),p2(l.p2)
{
cout<<"调用构造函数"<<endl;
}
Line(Point xp1,Point xp2):p1(xp1),p2(xp2)
{
len=sqrt( (double)( p1.GetX()-p2.GetX())*(p1.GetX()-p2.GetX())+(p1.GetY()-p1.GetY())*(p1.GetY()-p1.GetY()) );
}
float GetLen()
{
return len;
}
Point GetPoint1()
{
return p1;
}
Point GetPoint2()
{
return p2;
}
};
int main()
{
Point p1(10,10);
Point p2(1,1);
Line l1;
Line l2(p1,p2);
return 0;
}