注册 登录
编程论坛 C++教室

请高手帮忙给看一下,是哪里的错,不胜感激!

司徒瑾贤 发布于 2012-03-10 23:17, 353 次点击
程序代码:
[local]1[/local]
#include
#include
using namespace std;

class Point{
    public:
        Point(){};
        Point(int x,int y);
        Point(Point &p);
        ~Point(){};
        friend class Line;
        friend class Square;
        //friend float CalculateLength(Point &p1,Point &p2);
    private:
        int    X,Y;
};
Point::Point(int x,int y){
    X=x;   
    Y=y;
}
Point::Point(Point &p){
    X=p.X;
    Y=p.Y;
}
class Line{
    public:
    Line(Point p1,Point p2);   
    float CalculateLength(){
    float  length;
    return length=(float)sqrt(pow((P1.X-P2.X),2)+pow((P1.Y-P2.Y),2));
    }
    friend class Square;
    private:
        Point P1,P2;
};
Line::Line(Point p1,Point p2){
    P1=p1;
    P2=p2;
}
class Square{
    public:
        Square(Line Lin1,Line Lin2);
        float CalculateSquare(){
        float  square;
        float  line1,line2;
        line1=(float)sqrt(pow((L1.P1.X-L1.P2.X),2)+pow((L1.P1.Y-L1.P2.Y),2));
        line1=(float)sqrt(pow((L2.P1.X-L2.P2.X),2)+pow((L2.P1.Y-L2.P2.Y),2));
        return square=line1*line2;
    }           
    private:
        Line L1,L2;
};
Square::Square(Line Lin1,Line Lin2){
    L1=Lin1;
    L2=Lin2;
}

//float CalculateLength(Point &p1,Point &p2){
//    float  length;
//    return length=(float)sqrt(pow((p1.X-p2.X),2)+pow((p1.Y-p2.Y),2));
//}


int main(void){
    Point xp1(0,3),xp2(4,0);
    Line  L1(xp1,xp2);
    Line  L2(L1);
    Square s1(L1,L2);
    cout<<S1.CALCULATESQUARE()<<ENDL;
   
    return 0;
}
只有本站会员才能查看附件,请 登录
Square的构造函数有错吗? 编译的时候说这里有问题,我有点搞不清楚。

[ 本帖最后由 司徒瑾贤 于 2012-3-10 23:20 编辑 ]
2 回复
#2
Wu_Roc2012-03-11 21:03
类是不能直接用‘ = ’号赋值的。。。。。
    L1=Lin1;
    L2=Lin2;
#3
Wu_Roc2012-03-11 21:31
说错了。。。。。好吧  是构造函数除了问题。。是line的构造函数,当你给了Line::Line(Point p1,Point p2)  系统不会提供默认构造函数,但是你形成形参时Square::Square(Line Lin1,Line Lin2)时就错了。。。你上面那个PIONT对的就是因为提供了 Point(){};
不好意思~

1