| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 576 人关注过本帖
标题:[求助]一道类和对象的问题
只看楼主 加入收藏
hanxin729
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-11-25
收藏
 问题点数:0 回复次数:1 
[求助]一道类和对象的问题
#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.
搜索更多相关主题的帖子: point line 对象 double 
2006-12-02 22:36
forever043
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2006-10-15
收藏
得分:0 
class line
{
//...
};

学操作系统真的好郁闷啊.........
2006-12-03 11:56
快速回复:[求助]一道类和对象的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023558 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved