C++高手来帮我看一下

来源:百度知道 编辑:UC知道 时间:2024/05/15 12:54:46
#include <iostream.h>
#include <math.h>
class point
{
public :
point(double a,double b);
point(point &p);
~point();
double Len(point p);
double GetX();
double GetY();
private :
double x,y;
};
class Traingle
{
public :
Traingle(point n,point m,point s);
Traingle(Traingle & T);
~Traingle();
double Getlen();
private :
point p1,p2,p3;
};

double point ::Len(point p)
{
return sqrt((p.x-x)*(p.x-x)+(p.y-y)*(p.y-y));
}
point ::point(double a,double b)
{
x=a;
y=b;
}
point::point(point &p)
{
x=p.x;
y=p.y;
}
point :: ~point(){}
double point ::GetX()
{
return x;
}
double point ::GetY()
{
return y;
}
Traingle ::Traingle(point n,point m ,point s): p1(n),p2(m),p3(s)
{
}
Traingle ::Traingle(

好像没有大问题。
只是

double Traingle::Getlen()
{
return (p1.Len()+p2.Len()+p3.Len());
}

len是带参数的。
return (p1.Len(p2)+p2.Len(p3)+p3.Len(p1));

还有参数用 const point & 传指针好一些。
你的类应该有 = 符号的重定义。
还有好的习惯是析构函数用 virtual.