24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 1180  |  回复: 5

cw277

木虫 (正式写手)

[求助] 这个c++小程序编译的错误很奇怪~~

明明语法上应该没有错误~~
回复此楼

» 本帖附件资源列表

  • 欢迎监督和反馈:小木虫仅提供交流平台,不对该内容负责。
    本内容由用户自主发布,如果其内容涉及到知识产权问题,其责任在于用户本人,如对版权有异议,请联系邮箱:xiaomuchong@tal.com
  • 附件 1 : 程序.rar
  • 2012-09-26 16:05:12, 86.56 K

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

感谢生活让我慢慢学会控制自己的情绪,学会包容与忍耐,学会不再去期待
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
回帖置顶 ( 共有1个 )

cw277

木虫 (正式写手)

cw277: 回帖置顶 2012-09-27 08:46:54
代码如下:

//POINT.H
#ifndef _POINT_H
#define _POINT_H

class Point
{public:
  Point(float=0,float=0);
  void setPoint(float,float);
  float getX() const {return x;}
  float getY() const {return y;}
  friend ostream & operator<<(ostream &,const Point &;
protected:
  float x,y;
};
#endif


//CIRCLE.H
#include "point.h"
#ifndef _CIRCLE_H
#define _CIRCLE_H

class Circle:public Point
{public:
  Circle(float x=0,float y=0,float r=0);
  void setRadius(float);
  float getRadius() const;
  float area () const;
  friend ostream &operator<<(ostream &,const Circle &;
protected:
  float radius;
};
#endif

//CYLINDER.H
#include "circle.h"
#ifndef _CYLINDER_H
#define _CYLINDER_H

class Cylinder:public Circle
{public:
  Cylinder (float x=0,float y=0,float r=0,float h=0);
  void setHeight(float);
  float getHeight() const;
  float area() const;
  float volume() const;
  friend ostream& operator<<(ostream&,const Cylinder&;
protected:
  float height;
};
#endif


//POINT.CPP
#include "point.h"
Point:oint(float a,float b)
{x=a;y=b;}

void Point::setPoint(float a,float b)
{x=a;y=b;}

ostream & operator<<(ostream &output,const Point &p)
{output<<"["< return output;
}


//CIRCLE.CPP
//#include
#include "circle.h"
Circle::Circle(float a,float b,float r)oint(a,b),radius(r){}

void Circle::setRadius(float r)
{radius=r;}

float Circle::getRadius() const {return radius;}

float Circle::area() const
{return 3.14159*radius*radius;}

ostream &operator<<(ostream &output,const Circle &c)
{output<<"Center=["< return output;
}


//CYLINDER.CPP
#include "cylinder.h"

Cylinder::Cylinder(float a,float b,float r,float h)
    :Circle(a,b,r),height(h){}

void Cylinder::setHeight(float h){height=h;}

float Cylinder::getHeight() const {return height;}

float Cylinder::area() const
{ return 2*Circle::area()+2*3.14159*radius*height;}

float Cylinder::volume() const
{return Circle::area()*height;}

ostream &operator<<(ostream &output,const Cylinder& cy)
{output<<"Center=["<        <<"\narea="< return output;
}

///main.cpp
#include      //如用VC++应改为∶#include  
using namespace std;    //如用VC++应取消此行
#include "point.h"
#include "circle.h"
#include "cylinder.h"
#include "point.cpp"
#include "circle.cpp"
#include "cylinder.cpp"
int main()
{Cylinder cy1(3.5,6.4,5.2,10);
cout<<"\noriginal cylinder:\nx="<      <      <<", volume="< cy1.setHeight(15);
cy1.setRadius(7.5);
cy1.setPoint(5,5);
cout<<"\nnew cylinder:\n"< Point &pRef=cy1;
cout<<"\npRef as a point:"< Circle &cRef=cy1;
cout<<"\ncRef as a Circle:"< return 0;
}
感谢生活让我慢慢学会控制自己的情绪,学会包容与忍耐,学会不再去期待
4楼2012-09-27 08:46:15
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
普通回帖

libralibra

至尊木虫 (著名写手)

骠骑将军

【答案】应助回帖


感谢参与,应助指数 +1
cw277: 金币+1, 有帮助, 文件有好几个。 2012-09-26 18:22:54
直接把代码贴在贴子里吧
matlab/VB/python/c++/Java写程序请发QQ邮件:790404545@qq.com
2楼2012-09-26 17:35:36
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

bemoner

金虫 (正式写手)

把代码贴出来,帮你看一下!
3楼2012-09-26 22:37:22
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

suhhyuan

铁虫 (初入文坛)

【答案】应助回帖

★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★
cw277: 金币+19, ★★★★★最佳答案, 谢谢指点,那我现在你QQ了, 以后有什么问题可以向你请教~ 2012-10-02 18:41:12
我找到问题了:
1、这个工程类型本身就是个问题,它现在是windows应用程序的,应该改为控制台应用程序;
2、注意:在xt12-1.cpp中使用include 中显式引入头文件和对应的cpp文件,不要轻易把cpp文(除包含main()函数的之外)件包含在项目中(通过右键添加到项目,否则会出现大量怪异的错误)。可以这样说(不是绝对的哦):一个项目中只包含一个cpp文件中(引入了其他cpp文件)和多个头文件(编译器会自动包含近来)。转到正题,就是把除xt12-1.cpp之外的.cpp文件从项目中移除(不是删除);
3、把:
#include
using namespace std;
改为:
#include

这是VC++6.0的问题,在VS中不需要此步;

结束!!!

有问题联系我993007254
5楼2012-10-02 11:05:43
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

suhhyuan

铁虫 (初入文坛)

哦,出了一个bug,不好意思。
吧第三步中的

#include

应该为

#include
6楼2012-10-02 11:11:32
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 cw277 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 调剂 +9 不逢春 2026-04-05 10/500 2026-04-06 11:58 by 考研学校招点人
[考研] 一志愿C9的化学工程(085602) 340分,感觉校内调剂无望,求调剂 +12 万事宜臻 2026-04-04 12/600 2026-04-06 07:46 by 无际的草原
[考研] 生物与医药求调剂 +5 heguanhua 2026-04-05 6/300 2026-04-05 22:58 by Hdyxbekcb
[考研] 081200-11408-276学硕求调剂 +4 崔wj 2026-04-04 5/250 2026-04-05 14:06 by imissbao
[考研] 318求调剂 +11 ykyhsa 2026-04-05 13/650 2026-04-05 12:44 by aidndnjck
[考研] 312求调剂 +3 Say Never 2026-04-04 3/150 2026-04-05 11:19 by guoweigw
[考研] 283分求调剂 +9 试试看呗 2026-04-04 9/450 2026-04-05 10:27 by 果冻大王
[考研] +5 化工专硕323分 2026-04-04 5/250 2026-04-05 08:02 by 544594351
[考研] 324求调剂 +9 想上学求调 2026-04-03 9/450 2026-04-04 23:57 by 果冻大王
[考研] 考研调剂 +6 15615482637 2026-04-04 6/300 2026-04-04 22:43 by yu221
[考研] 085400电子信息319求调剂(接受跨专业调剂) +5 星星不眨眼喽 2026-04-03 6/300 2026-04-04 21:50 by hemengdong
[考研] 一志愿双非085502,267分,过四级求调剂 +3 再忙也要吃饭啊 2026-04-03 3/150 2026-04-04 05:03 by gswylq
[考研] 265求调剂 +17 林深温澜 2026-04-01 20/1000 2026-04-04 01:09 by userper
[考研] 288求调剂 一志愿哈工大 材料与化工 +39 洛神哥哥 2026-03-31 41/2050 2026-04-03 21:51 by qlm5820
[考研] 材料与化工调剂一志愿大连海事085600,349 +11 吃的不少 2026-03-30 11/550 2026-04-03 18:05 by Jimmyandyou
[考研] 285求调剂 +7 AZMK 2026-04-02 9/450 2026-04-03 11:12 by wanwan00
[考研] 312求调剂 +4 赊月色 2026-04-02 5/250 2026-04-03 08:21 by fangshan711
[考研] 354求调剂 +4 lxb598 2026-03-31 5/250 2026-04-02 09:55 by Jaylen.
[考研] 08生物与医药专硕初试346找调剂 +6 dianeeee 2026-04-01 7/350 2026-04-02 08:23 by guoweigw
[考研] 物理学调剂 +4 小羊36 2026-03-30 4/200 2026-03-31 16:16 by lishahe
信息提示
请填处理意见