P.s__葬爱 发表于 2014-8-6 10:20:00

类的组合错误问题

#include<iostream>
#include<cmath>
using namespace std;
class Point
{
        public:
        Point(int xx=0,int yy=0)
                {
                x=xx;
                y=yy;
                }
        Point(Point &p);
        int getX()
        {
                return x;
        }
        int getY()
        {
                return y;
        }
        private:
                int x,y;
};
Point::Point(*p)
{
        x=p.x;
        y=p.y;
        cout<<"Calling the copy constructor of Point"<<endl;
}
//类的组合
class Line
{
        public line(Point xp1, Point xp2);
        line(Line&l);
        double getlen()
        {
                return len;
        }
        private:
        Point P1,P2;
        double len;
};
//组合类的构造函数
Line::Line(Point xp1,Point xp2):p1(xp1),p2(xp2)
{
        cout<<"Calling constructor of Line"<<endl;
        double x=static_cast<double>(p1.getX()-p2.getX());
        double y=static_cast<double>(p1.getY()-p2.getY());
        len=sqrt(x*x+y*y);
}
//组合类的复制构造函数
Line::Line(Line &l):p1(1.p1),p2(1.p2)
{
        cout<<"Calling the copy constructor of Line"<<endl;
        len=l.len;
}
int main()
{
        Point myp1(1,1),myp2(4,5);
        Line line(myp1,myp2);
        Line line2(line);
        cout<<"The length of the Line is:";
        cout<<Line.getLen()<<endl;
        cout<<"the length of the line2 is:"
        colut<<line2.getLen()<<endl;
        return 0;
}
1>e:\学习\c++\c++小程序\第四章\第四章\线(类的组合).cpp(34) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\学习\c++\c++小程序\第四章\第四章\线(类的组合).cpp(34) : warning C4183: “line”: 缺少返回类型;假定为返回“int”的成员函数
1>e:\学习\c++\c++小程序\第四章\第四章\线(类的组合).cpp(35) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\学习\c++\c++小程序\第四章\第四章\线(类的组合).cpp(35) : warning C4183: “line”: 缺少返回类型;假定为返回“int”的成员函数
1>e:\学习\c++\c++小程序\第四章\第四章\线(类的组合).cpp(45) : error C2511: “Line::Line(Point,Point)”: “Line”中没有找到重载的成员函数
1>      e:\学习\c++\c++小程序\第四章\第四章\线(类的组合).cpp(32) : 参见“Line”的声明
1>e:\学习\c++\c++小程序\第四章\第四章\线(类的组合).cpp(69) : fatal error C1004: 发现意外的文件尾

P.s__葬爱 发表于 2014-8-6 22:02:20

jianyuling00 发表于 2014-8-6 11:48
附上修改后的代码:
注意声明要与使用的变量或者函数名一致,不要声明时小写,运用时大写;
语句末尾记得 ...

谢谢啊

墙角君 发表于 2014-8-6 22:14:58

。。。。。   
页: [1]
查看完整版本: 类的组合错误问题