24小时热门版块排行榜    

查看: 1311  |  回复: 5
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

cw277

木虫 (正式写手)

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

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

» 本帖附件资源列表

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

» 猜你喜欢

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

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

bemoner

金虫 (正式写手)

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

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

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的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 国自然面上复盘~欢迎讨论 +5 晴天加油 2026-08-26 6/300 2026-08-27 04:49 by littlezl
[硕博家园] 售SCI一区T0P文章,我:8.O.55.1.O.54,科目齐全,可+急 +3 LIbGuocjEEYw 2026-08-26 4/200 2026-08-27 02:01 by Ie9AyIAvGbvs
[基金申请] 看板上这么多中的,有点像50人群里49个人都是骗子的那种感觉…… +3 a089 2026-08-26 3/150 2026-08-26 23:21 by young90
[基金申请] 我不理解! +15 Edward_pc 2026-08-26 23/1150 2026-08-26 20:34 by zzuzxg
[基金申请] 怎么查啊 +5 huang1991js 2026-08-26 5/250 2026-08-26 16:09 by Equinoxhua
[基金申请] 2026年8月25日国自然放榜前突然收到列入评审专家邮件,有关系吗? +25 木水思豆 2026-08-25 28/1400 2026-08-26 14:53 by draco1987
[基金申请] 能否退出参与的面上项目解除限项 +23 koalala 2026-08-24 26/1300 2026-08-26 14:29 by 宝贝虫子
[基金申请] 科研孤儿太难了 +21 我4大白菜 2026-08-20 22/1100 2026-08-26 11:29 by nlgza
[基金申请] 国合里面能看到了 +7 一怀馨秋 2026-08-26 7/350 2026-08-26 11:23 by zhaosm1982
[基金申请] 国际合作可查了,中了面上 +18 Ldrop2023 2026-08-26 18/900 2026-08-26 11:15 by cmrandy
[基金申请] 系统进不去 +4 yanglien 2026-08-26 5/250 2026-08-26 11:10 by wenfengw83
[基金申请] 怎么看青基中了没有啊 +4 叶九微 2026-08-26 4/200 2026-08-26 10:52 by xiacongxu
[基金申请] 今天务委会开完了,明天出结果吗 +19 angus9576 2026-08-25 23/1150 2026-08-26 10:03 by zp519
[基金申请] 牛来!米来!面来! +8 beefly 2026-08-26 8/400 2026-08-26 08:37 by xuzhipiao
[基金申请] 在坚冰还盖着北海的时候,我看到了怒放的梅花。 (金币+10) +6 ziyangfang 2026-08-25 9/450 2026-08-25 20:26 by huagongfeihu
[基金申请] 明天应该可查了!? +6 chengyan1220 2026-08-23 6/300 2026-08-25 19:45 by zfd97
[基金申请] 今日不放榜?网传国自然预计 8 月 27 日可查结果 +17 医学老男孩 2026-08-20 22/1100 2026-08-25 15:36 by 医学老男孩
[基金申请] 人气不行了 +11 fansofjerry 2026-08-21 11/550 2026-08-25 11:04 by 孤独的英雄6
[基金申请] 时间戳又变了 +13 wuchongjun 2026-08-20 19/950 2026-08-21 17:21 by 紫杉醇
[基金申请] 应该是下周三26日公布了吧? +4 哈哈蛤? 2026-08-21 4/200 2026-08-21 10:58 by Vivilian
信息提示
请填处理意见