| 查看: 1069 | 回复: 5 | ||
cw277木虫 (正式写手)
|
[求助]
这个c++小程序编译的错误很奇怪~~
|
|
| 明明语法上应该没有错误~~ |
» 本帖附件资源列表
-
欢迎监督和反馈:小木虫仅提供交流平台,不对该内容负责。
本内容由用户自主发布,如果其内容涉及到知识产权问题,其责任在于用户本人,如对版权有异议,请联系邮箱:xiaomuchong@tal.com - 附件 1 : 程序.rar
2012-09-26 16:05:12, 86.56 K
» 猜你喜欢
垃圾破二本职称评审标准
已经有19人回复
职称评审没过,求安慰
已经有53人回复
毕业后当辅导员了,天天各种学生超烦
已经有5人回复
26申博自荐
已经有3人回复
A期刊撤稿
已经有4人回复
» 本主题相关价值贴推荐,对您同样有帮助:
《C++程序设计语言(特别版) 》第1版第18次印刷(高清中/英文版)[PDF]
已经有557人回复
手机上的C/C++编译器,学编程的同学们有福了
已经有72人回复
请教一个fortran小程序编译出错的问题,谢谢
已经有9人回复
c++中的负数求模问题
已经有4人回复
【求助】C++编译报出的几个错误
已经有3人回复
【求助】怎么装visual C++编译器?
已经有4人回复
【求助】c++如何发布独立的程序?
已经有15人回复
【求助】C++程序所需内存远远大于物理内存怎么办?
已经有8人回复
【求助】为什么我编译了一个书本上的无错误的C++程序,却有这么多的错误?
已经有8人回复
【分享】C++基础知识下载
已经有3人回复
【分享】C++程序设计总结——学C++的朋友多注意!!!
已经有10人回复

cw277
木虫 (正式写手)
- 应助: 0 (幼儿园)
- 金币: 3886.9
- 散金: 1641
- 红花: 2
- 帖子: 931
- 在线: 454.7小时
- 虫号: 737380
- 注册: 2009-04-01
- 性别: GG
- 专业: 通信理论与系统
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<<"["< } //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=["< } //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=["< } ///main.cpp #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="< cy1.setRadius(7.5); cy1.setPoint(5,5); cout<<"\nnew cylinder:\n"< cout<<"\npRef as a point:"< cout<<"\ncRef as a Circle:"< } |

4楼2012-09-27 08:46:15
libralibra
至尊木虫 (著名写手)
骠骑将军
- 程序强帖: 40
- 应助: 817 (博后)
- 金币: 12914.1
- 红花: 64
- 帖子: 2238
- 在线: 287.3小时
- 虫号: 696514
- 注册: 2009-02-05
- 专业: 计算机软件

2楼2012-09-26 17:35:36
bemoner
金虫 (正式写手)
- 应助: 0 (幼儿园)
- 金币: 1161.2
- 散金: 12
- 红花: 1
- 帖子: 472
- 在线: 9.9小时
- 虫号: 852418
- 注册: 2009-09-20
- 专业: 信息安全
3楼2012-09-26 22:37:22
【答案】应助回帖
★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★
cw277: 金币+19, ★★★★★最佳答案, 谢谢指点,那我现在你QQ了, 以后有什么问题可以向你请教~ 2012-10-02 18:41:12
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
6楼2012-10-02 11:11:32













回复此楼
;
oint(float a,float b)
993007254