| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1622 人关注过本帖
标题:[求助]代码编译通不过
只看楼主 加入收藏
dubaoshi
Rank: 1
等 级:新手上路
帖 子:118
专家分:0
注 册:2006-9-22
收藏
 问题点数:0 回复次数:20 
[求助]代码编译通不过

下面的这个例子,我是按教程做的,可是编译不过,帮忙看一下,谢谢:)

#include<iostream>

class Rectangle
{
private:int itsTop;
int itsLeft;
int itsBotton;
int itsRight;
public:
Rectangle(int top,int left,int botton,int right);
~Rectangle(){};
int GetTop(){return itsTop};
int GetLeft(){return itsLeft};
int GetBotton(){return itsBotton};
int GetRight(){return itsRight};
void SetTop(int top){itsTop=top;};
void SetLeft(int left){itsLeft=left;};
void SetBotton(int botton){itsBotton=botton;};
void SetRight(int right){itsRight=right;};
int GetArea();
}
Rectangle::Rectangle(int top,int left,int botton,int right)
{     //编译停留在这里,提示的英文好象是构造器不能满足返回的类型(问的别人,我英语0级)
int itsTop=top;
int itsLeft=left;
int itsBotton=botton;
int itsRight=right;
}
int Rectangle::GetArea()
{
int Width=itsRight=itsLeft;
int Height=itsTop-itsBotton;
return Width*Height;
}

void main()
{
Rectangle MyRectangle(100,20,50,80);
int Area=MyRectangle.GetArea();
cout<<"Top:"<<MyRectangle.GetTop()<<endl;
cout<<"Left:"<<MyRectangle.GetLeft()<<endl;
cout<<"Botton:"<<MyRectangle.GetBotton()<<endl;
cout<<"Right:"<<MyRectangle.GetRight()<<endl;
cout<<"Area:"<<Area<<endl;
}


大侠帮忙,我请你喝酒

搜索更多相关主题的帖子: int Rectangle 编译 return 代码 
2006-11-04 10:33
uwe0709
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-10-12
收藏
得分:0 
你这个做的是矩形吗?
2006-11-04 10:48
dubaoshi
Rank: 1
等 级:新手上路
帖 子:118
专家分:0
注 册:2006-9-22
收藏
得分:0 
是的,终于有人回复了,没想到还是先提问的,嘿嘿

人行善,福虽未至,祸已远离;人行恶,祸虽未至,福已远离.
2006-11-04 10:51
uwe0709
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-10-12
收藏
得分:0 
那你的left,right,botton,top 表示的都是什么?不是只要一个长和宽不就行了吗?
2006-11-04 11:03
dubaoshi
Rank: 1
等 级:新手上路
帖 子:118
专家分:0
注 册:2006-9-22
收藏
得分:0 
人家例子就是这样做的,所以我一个字一个字敲进去的,顺便理解一下什么叫class。
可是编译的时候就是通不过,我也不知道怎么回事了,郁闷着呢,你要是知道的话,告诉我吧,谢谢。。。

人行善,福虽未至,祸已远离;人行恶,祸虽未至,福已远离.
2006-11-04 11:08
litcatyx
Rank: 1
等 级:新手上路
威 望:1
帖 子:151
专家分:0
注 册:2006-10-27
收藏
得分:0 
你的类定义最后没有加上;
.
Rectangle::Rectangle(int top,int left,int botton,int right)
{     //编译停留在这里,提示的英文好象是构造器不能满足返回的类型(问的别人,我英语0级)
int itsTop=top;
int itsLeft=left;
int itsBotton=botton;
int itsRight=right;
}

==>

Rectangle::Rectangle(int top,int left,int botton,int right)
{
itsTop=top;
itsLeft=left;
itsBotton=botton;
itsRight=right;
}


这几句
int GetTop(){return itsTop};
int GetLeft(){return itsLeft};
int GetBotton(){return itsBotton};
int GetRight(){return itsRight};
return xxxx后面加上;。


最后一个问题,你的botton应该是bottom,英语问题


2006-11-04 11:08
dubaoshi
Rank: 1
等 级:新手上路
帖 子:118
专家分:0
注 册:2006-9-22
收藏
得分:0 
我按你说的改了,可是还是通不过编译呢:(
郁闷死了,想一步步跟踪都不可以:(
再帮我一下呀!
要不你加我的QQ吧:34947903,谢谢啦!

人行善,福虽未至,祸已远离;人行恶,祸虽未至,福已远离.
2006-11-04 11:32
litcatyx
Rank: 1
等 级:新手上路
威 望:1
帖 子:151
专家分:0
注 册:2006-10-27
收藏
得分:0 
using namespace std;

2006-11-04 11:34
dubaoshi
Rank: 1
等 级:新手上路
帖 子:118
专家分:0
注 册:2006-9-22
收藏
得分:0 
还是不行啊,老大,你帮我弄完整了好不好呀?谢谢啦!我急着呢

人行善,福虽未至,祸已远离;人行恶,祸虽未至,福已远离.
2006-11-04 11:44
litcatyx
Rank: 1
等 级:新手上路
威 望:1
帖 子:151
专家分:0
注 册:2006-10-27
收藏
得分:0 
#include<iostream>

using namespace std;

class Rectangle
{
private:int itsTop;
int itsLeft;
int itsBotton;
int itsRight;
public:
Rectangle(int top,int left,int botton,int right);
~Rectangle(){};
int GetTop(){return itsTop;};
int GetLeft(){return itsLeft;};
int GetBotton(){return itsBotton;};
int GetRight(){return itsRight;};
void SetTop(int top){itsTop=top;};
void SetLeft(int left){itsLeft=left;};
void SetBotton(int botton){itsBotton=botton;};
void SetRight(int right){itsRight=right;};
int GetArea();
};
Rectangle::Rectangle(int top,int left,int botton,int right)
{
itsTop=top;
itsLeft=left;
itsBotton=botton;
itsRight=right;
}
int Rectangle::GetArea()
{
int Width=itsRight=itsLeft;
int Height=itsTop-itsBotton;
return Width*Height;
}

int main()
{
Rectangle MyRectangle(100,20,50,80);
int Area=MyRectangle.GetArea();
cout<<"Top:"<<MyRectangle.GetTop()<<endl;
cout<<"Left:"<<MyRectangle.GetLeft()<<endl;
cout<<"Botton:"<<MyRectangle.GetBotton()<<endl;
cout<<"Right:"<<MyRectangle.GetRight()<<endl;
cout<<"Area:"<<Area<<endl;
return 0;
}

2006-11-04 12:04
快速回复:[求助]代码编译通不过
数据加载中...
 
   



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

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