请高手帮忙给看一下,是哪里的错,不胜感激!
程序代码:
[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 编辑 ]