[求助]一道类和对象的问题
#include"iostream"#include"cmath"
using namespace std;
class point
{public:
point(int xx=00,int yy=00){X=xx,Y=yy;}
point(point&p);
int GetX()
{return X;}
int GetY()
{return Y;}
private:
int X,Y;};
point::point(point&p)
{X=p.X;
Y=p.Y;
cout<<"The first get kaob hanshu"<<endl;
}
//类的组合
class line
{public:
line(point xp1,point xp2);
line(line&);
double Getlen() {return len;}
private:
point p1,p2;
double len;}
//组合类的构造函数
line::line(point xp1,point xp2):p1(xp1),p2(xp2)
{cout<<"构造函数被调用"<<endl;
double X=double(p1.GetX()-p2.GetX());
double Y=double(p1.GetY()-p2.GetY());
double len=sqrt(X*X+Y*Y);}
//组合类的拷贝构造函数
line::line(line&l):p1(l.p1),p2(l.p2)
{cout<<"line的拷贝构造函数被调用";
double len=l.len;}
void main()
{point myp1(1,1),myp2(4,5);
line myl1(myp1,myp2);
line myl2(myl1);
cout<<"The len of the line is:";
cout<<myl1.Getlen()<<endl;
cout<<"The len of myl2 is:";
cout<<myl2.Getlen()<<endl;
}
有如此提示:
Cpp10a.cpp
e:\c++编程\cpp10a.cpp(29) : error C2533: 'line::line' : constructors not allowed a return type
e:\c++编程\cpp10a.cpp(40) : error C2264: 'line::line' : error in function definition or declaration; function not called
Error executing cl.exe.