找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 1990|回复: 3

难道又是编译器的问题???

[复制链接]
发表于 2009-11-3 00:40:58 | 显示全部楼层 |阅读模式 IP:江苏扬州
这是教材上用来讲类的组合的一个例子,我基本上跟书上写的一样,代码这样:大虾们请指点一下小弟

#include<iostream>
#include<cmath>
using namespace std;
class Point
{
private:
double x;
double y;
public:
Point(double x,double y){x=x;y=y;cout<<"Point类构造函数被调用"<<endl;}
Point(Point & p);

~Point(){}
double getx(){}
double gety();
}
Point::Point(Point & p)//////////////////////error C2533: 'Point::Point' : constructors not allowed a return type

{
x=p.x;
y=p.y;
cout<<"Point类拷贝构造函数被调用"<<endl;
}
double Point::getx()
{
return x;
}
double Point::gety()
{
return y;
}
class Line
{
private:
Point p1,p2;
double leng;
public:
Line(Point p1,Point p2);
Line(Line &);
~Line(){}
double getl();
}
Line::Line(Point p1,Point p2):p1(p1),p2(p2)//////////////////////////////////同上
{
double xl=p1.getx()-p2.getx();
double yl=p1.gety()-p2.gety();
leng=sqrt(xl*xl+yl*yl);
cout<<"Line类构造函数被调用"<<endl;
}
Line::Line(Line & li):p1(li.p1),p2(li.p2)
{
leng=li.leng;
cout<<"Line类拷贝构造函数被调用"<<endl;
}
void main()
{
Point p1(3,4);
Point p2(7,8);
Line l1(p1,p2);
Line l2(l1);
cout<<"The length of l1 is:"<<l1.getl()<<endl;
cout<<"The length of l2 is:"<<l2.getl()<<endl;
return ;
}



这是全部的编译报错信息:

--------------------Configuration: Line - Win32 Debug--------------------
Compiling...
Line.cpp
D:\My Program\Line\Line.cpp(18) : error C2533: 'Point::Point' : constructors not allowed a return type
D:\My Program\Line\Line.cpp(43) : error C2533: 'Line::Line' : constructors not allowed a return type
D:\My Program\Line\Line.cpp(44) : error C2264: 'Point::Point' : error in function definition or declaration; function not called
D:\My Program\Line\Line.cpp(44) : error C2264: 'Point::Point' : error in function definition or declaration; function not called
D:\My Program\Line\Line.cpp(51) : error C2264: 'Point::Point' : error in function definition or declaration; function not called
D:\My Program\Line\Line.cpp(51) : error C2264: 'Point::Point' : error in function definition or declaration; function not called
D:\My Program\Line\Line.cpp(59) : error C2264: 'Line::Line' : error in function definition or declaration; function not called
Error executing cl.exe.
Line.obj - 7 error(s), 0 warning(s)
发表于 2009-11-3 00:41:04 | 显示全部楼层 IP:江苏扬州
唉,太丢人了,连这个最基本的问题都忘了,不应该不应该啊,大家别笑话俺呀
回复

使用道具 举报

发表于 2009-11-3 00:41:16 | 显示全部楼层 IP:江苏扬州
俺也是新手
回复

使用道具 举报

发表于 2009-11-3 00:41:23 | 显示全部楼层 IP:江苏扬州
#include<iostream>
#include<cmath>
using namespace std;
class Point
{
private:
double x;
double y;
public:
Point(double x,double y){x=x;y=y;cout<<"Point类构造函数被调用"<<endl;}
Point(Point & p);

~Point(){};
double getx();
double gety();
};//这里少了分号
Point::Point(Point & p)//////////////////////error C2533: 'Point::Point' : constructors not allowed a return type
{
x=p.x;
y=p.y;
cout<<"Point类拷贝构造函数被调用"<<endl;
}
double Point::getx()
{
return x;
}
double Point::gety()
{
return y;
}
class Line
{
private:
Point p1,p2;
double leng;
public:
Line(Point p1,Point p2);
Line(Line &);
~Line(){}
double getl();//这里你没有定义
};//同上少分号
Line::Line(Point p1,Point p2):p1(p1),p2(p2)//////////////////////////////////同上
{
double xl=p1.getx()-p2.getx();
double yl=p1.gety()-p2.gety();
leng=sqrt(xl*xl+yl*yl);
cout<<"Line类构造函数被调用"<<endl;
}
Line::Line(Line & li):p1(li.p1),p2(li.p2)
{
leng=li.leng;
cout<<"Line类拷贝构造函数被调用"<<endl;
}
double Line::getl()
{
return leng;
}
int main()
{
Point p1(3,4);
Point p2(7,8);
Line l1(p1,p2);
Line l2(l1);
cout<<"The length of l1 is:"<<l1.getl()<<endl;
cout<<"The length of l2 is:"<<l2.getl()<<endl;
system("pause");
return 0;

}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-9-30 03:25 , Processed in 0.212080 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表