24小时热门版块排行榜    

查看: 1324  |  回复: 5

cw277

木虫 (正式写手)

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

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

» 本帖附件资源列表

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

» 猜你喜欢

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

感谢生活让我慢慢学会控制自己的情绪,学会包容与忍耐,学会不再去期待
已阅   回复此楼   关注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的回帖

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的回帖

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 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 投票:  有多少人是今天查系统知道结果的? +17 爱看书的可乐 2026-08-26 19/950 2026-09-02 00:19 by xiangy672
[基金申请] 面上函评意见出来了,像什么等级? 20+4 Tsingking1 2026-08-27 17/850 2026-09-01 19:51 by 超级无敌华子
[文学芳草园] 梦想 +5 myrtle 2026-08-26 7/350 2026-09-01 15:18 by myrtle
[论文投稿] 小白求助 投论文要求的highlights应该如何写 5+3 l1963982152 2026-08-29 4/200 2026-09-01 09:04 by 北京莱茵编辑
[基金申请] 怎么看青基中了没有啊 +6 叶九微 2026-08-26 6/300 2026-08-31 23:54 by yudaoqian88
[基金申请] 国社科又开始会评了,不知道这次命运如何 +7 雨打竹帘 2026-08-30 11/550 2026-08-31 23:16 by hittle2008
[基金申请] 哪位高人中了,把查询到的截图贴出来让我看看,让我长长见识 +6 yuleib84 2026-08-26 7/350 2026-08-31 19:46 by 鱼翔浅底1
[基金申请] 能否申诉? +7 echo8914667 2026-08-30 8/400 2026-08-31 17:00 by yihongxu
[基金申请] 29号明天会评吗 +4 笨笨唐 2026-08-28 4/200 2026-08-31 09:30 by huixian257
[基金申请] 为什么到现在没收到通知? +5 tannykie 2026-08-29 5/250 2026-08-30 21:05 by purplejack
[基金申请] 有没有仍没收到信息的 +7 德尚中行 2026-08-27 8/400 2026-08-30 20:52 by purplejack
[基金申请] 国自然面上复盘~欢迎讨论 (金币+15) +15 晴天加油 2026-08-26 16/800 2026-08-29 18:28 by symmetry
[基金申请] 怎么查啊 +6 huang1991js 2026-08-26 6/300 2026-08-28 08:42 by winsaint
[基金申请] 看板上这么多中的,有点像50人群里49个人都是骗子的那种感觉…… +5 a089 2026-08-26 6/300 2026-08-27 14:05 by jonewore
[基金申请] 为什么 国际(地区)合作与交流项目 没有放榜? 10+3 majunge000 2026-08-26 11/550 2026-08-27 08:42 by 北京莱茵编辑
[基金申请] 我不理解! +15 Edward_pc 2026-08-26 23/1150 2026-08-26 20:34 by zzuzxg
[基金申请] 国合里面能看到了 +7 一怀馨秋 2026-08-26 7/350 2026-08-26 11:23 by zhaosm1982
[基金申请] 系统进不去 +4 yanglien 2026-08-26 5/250 2026-08-26 11:10 by wenfengw83
[基金申请] 项目信息和经费信息在系统里都可以看到了 +6 wittyboy 2026-08-26 14/700 2026-08-26 10:55 by wittyboy
[基金申请] 牛来!米来!面来! +8 beefly 2026-08-26 8/400 2026-08-26 08:37 by xuzhipiao
信息提示
请填处理意见