| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1460 人关注过本帖
标题:教材上的例子,在C++6.0下总是编译不通过
只看楼主 加入收藏
marenshi
Rank: 2
等 级:论坛游民
帖 子:23
专家分:17
注 册:2009-10-31
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:8 
教材上的例子,在C++6.0下总是编译不通过
请教在C++6.0环境编程的注意问题。
搜索更多相关主题的帖子: 教材 例子 编译 
2010-06-13 23:59
audioMan86
Rank: 2
等 级:论坛游民
帖 子:29
专家分:73
注 册:2010-6-12
收藏
得分:3 
你不列出错误信息,如何帮你了

console游戏开发中,MSN: wushuang212@
2010-06-14 12:45
南国利剑
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:29
帖 子:1165
专家分:3536
注 册:2010-4-12
收藏
得分:3 
请楼主把详细情况说明一下。

南国利剑
2010-06-14 14:49
华仔li
Rank: 2
来 自:山东济南
等 级:论坛游民
帖 子:14
专家分:54
注 册:2010-6-9
收藏
得分:3 
你用的VC++是不是中文版的?
2010-06-14 23:22
marenshi
Rank: 2
等 级:论坛游民
帖 子:23
专家分:17
注 册:2009-10-31
收藏
得分:0 
是啊,是中文版的
2010-06-15 20:48
marenshi
Rank: 2
等 级:论坛游民
帖 子:23
专家分:17
注 册:2009-10-31
收藏
得分:0 
#include<iostream.h>
class Shape
{public:
virtual float area() const {return 0.0;}
virtual float volume() const {return 0.0;}
virtual void shapename() const =0;
};
class Point:public Shape
{public:
Point(float=0,float=0);
void setpoint(float =0,float =0);
float getX() const{return x;}
float getY() const{return y;}
virtual void shapename() const {cout<<"Point:";}
friend ostream &operator<<(ostream&, const Point &);
protected:
    float x;
    float y;
};
Point::Point(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<<"["<<p.getX()<<","<<p.getY()<<"]";
return output;
}
class Circle:public Point
{public:
Circle(float x=0,float y=0,float r=0 );
void setradius(float);
float getradius()const;
virtual float area() const;
virtual void shapename() const {cout<<"Circle:";}
friend ostream &operator<<(ostream &,const Circle &);
protected:
    float radius;
};
Circle::Circle(float a,float b,float r):Point(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,Circle &c)
{output<<"["<<c.getX()<<","<<c.getY()<<"],r="<<c.getradius();
return output;
}
class Cylinder:public Circle
{public:
Cylinder(float x=0,float y=0,float r=0,float h=0);
void setheight(float);
virtual float area()const;
virtual float volume() const;
virtual void  shapename() const{cout<<"Cylinder:";}
friend ostream &operator<<(ostream &,Cylinder &);
protected:
    float heigth;
};
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::area() const
{return 2*Circle::area()+2*3.14159*radius*height;}
float Cylinder::volume()
{return Circle::area()*height;
}
ostream &operator<<(ostream &output,Cylinder &cy)
{output<<"["<<cy.getX()<<","<<cy.getY()<<"],r="<<cy.getradius()<<",h="<<cy.getheight();
return output;
}
int main()
{Point point(3.2,4.5);
Circle circle(2.4,1.2,5.6);
Cylinder(3.5,6.4,5.2,10.5);
point.shapename();
cout<<point<<endl;
circle.shapename();
cout<<circle<<endl;
cylinder.shapename();
cout<<cylinder<<endl;
Shape *p;
p->shapename();
cout<<"x="<<point.getX()<<"y="<<point.getY()<<"\narea="<<p->area()<<"\nvolume="<<p->volume()<<"\n\n";
p=&circle;
p->shapename();
cout<<"x="<<circle.getX()<<"y="<<circle.getY()<<"\nnarea="<<p->area()<<"\nvolume="<<p->volume()<<"\n\n";
p=&cylinder;
cout<<"x="<<cylinder.getX()<<"y="<<cylinder.getY()<<"\narea"<<p->area()<<"\nvolume="<<p->volume()<<"\n\n";
return 0;
}
C++6.0中文版,编译通不过。
:\我的文档\桌面\xx.cpp(44) : warning C4244: 'return' : conversion from 'double' to 'float', possible loss of data
d:\我的文档\桌面\xx.cpp(60) : error C2065: 'height' : undeclared identifier
d:\我的文档\桌面\xx.cpp(60) : warning C4244: '=' : conversion from 'float' to 'int', possible loss of data
d:\我的文档\桌面\xx.cpp(62) : warning C4244: '=' : conversion from 'float' to 'int', possible loss of data
d:\我的文档\桌面\xx.cpp(64) : warning C4244: 'return' : conversion from 'double' to 'float', possible loss of data
d:\我的文档\桌面\xx.cpp(66) : error C2511: 'volume' : overloaded member function 'float (void)' not found in 'Cylinder'
        d:\我的文档\桌面\xx.cpp(49) : see declaration of 'Cylinder'
d:\我的文档\桌面\xx.cpp(69) : error C2039: 'getheight' : is not a member of 'Cylinder'
        d:\我的文档\桌面\xx.cpp(49) : see declaration of 'Cylinder'
d:\我的文档\桌面\xx.cpp(73) : warning C4305: 'argument' : truncation from 'const double' to 'float'
d:\我的文档\桌面\xx.cpp(74) : warning C4305: 'argument' : truncation from 'const double' to 'float'
d:\我的文档\桌面\xx.cpp(74) : warning C4305: 'argument' : truncation from 'const double' to 'float'
d:\我的文档\桌面\xx.cpp(74) : warning C4305: 'argument' : truncation from 'const double' to 'float'
d:\我的文档\桌面\xx.cpp(75) : warning C4305: 'argument' : truncation from 'const double' to 'float'
d:\我的文档\桌面\xx.cpp(75) : warning C4305: 'argument' : truncation from 'const double' to 'float'
d:\我的文档\桌面\xx.cpp(80) : error C2065: 'cylinder' : undeclared identifier
d:\我的文档\桌面\xx.cpp(80) : error C2228: left of '.shapename' must have class/struct/union type
d:\我的文档\桌面\xx.cpp(88) : error C2440: '=' : cannot convert from 'int *' to 'class Shape *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
d:\我的文档\桌面\xx.cpp(89) : error C2228: left of '.getX' must have class/struct/union type
d:\我的文档\桌面\xx.cpp(89) : error C2228: left of '.getY' must have class/struct/union type
执行 cl.exe 时出错.

xx.obj - 1 error(s), 0 warning(s)
高手指教。谢谢。我都对C++开始灰心丧气了。
2010-06-15 20:56
cnfarer
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:179
帖 子:3330
专家分:21157
注 册:2010-1-19
收藏
得分:3 
#include<iostream>
//#include<stdlib.h>
using namespace std;
class Shape
{public:
virtual float area() const {return 0.0;}
virtual float volume() const {return 0.0;}
virtual void shapename() const =0;
};
class Point:public Shape
{public:
Point(float=0,float=0);
void setpoint(float =0,float =0);
float getX() const{return x;}
float getY() const{return y;}
virtual void shapename() const {cout<<"Point:";}
friend ostream &operator<<(ostream&, const Point &);
protected:
    float x;
    float y;
};
Point::Point(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<<"["<<p.getX()<<","<<p.getY()<<"]";
return output;
}
class Circle:public Point
{public:
Circle(float x=0,float y=0,float r=0 );
void setradius(float);
float getradius()const;
virtual float area() const;
virtual void shapename() const {cout<<"Circle:";}
friend ostream &operator<<(ostream &,const Circle &);
protected:
    float radius;
};
Circle::Circle(float a,float b,float r):Point(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,Circle &c)
{output<<"["<<c.getX()<<","<<c.getY()<<"],r="<<c.getradius();
return output;
}
class Cylinder:public Circle
{public:
Cylinder(float x=0,float y=0,float r=0,float h=0);
void setheight(float);
virtual float area()const;
virtual float volume() const;
virtual void  shapename() const{cout<<"Cylinder:";}
virtual float getheight() const{return height;}
friend ostream &operator<<(ostream &,Cylinder &);
protected:
    float height;
};
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::area() const
{return 2*Circle::area()+2*3.14159*radius*height;}
float Cylinder::volume() const
{return Circle::area()*height;
}
ostream &operator<<(ostream &output,Cylinder &cy)
{output<<"["<<cy.getX()<<","<<cy.getY()<<"],r="<<cy.getradius()<<",h="<<cy.getheight();
return output;
}
int main()
{Point point(3.2,4.5);
Circle circle(2.4,1.2,5.6);
Cylinder cylinder(3.5,6.4,5.2,10.5);
point.shapename();
cout<<point<<endl;
circle.shapename();
cout<<circle<<endl;
cylinder.shapename();
cout<<cylinder<<endl<<endl;
Shape *p;
p=&point;
p->shapename();
cout<<"x="<<point.getX()<<"y="<<point.getY()<<"\narea="<<p->area()<<"\nvolume="<<p->volume()<<"\n\n";
p=&circle;
p->shapename();
cout<<"x="<<circle.getX()<<"y="<<circle.getY()<<"\narea="<<p->area()<<"\nvolume="<<p->volume()<<"\n\n";
p=&cylinder;
cout<<"x="<<cylinder.getX()<<"y="<<cylinder.getY()<<"\narea="<<p->area()<<"\nvolume="<<p->volume()<<"\n\n";

return 0;
}

★★★★★为人民服务★★★★★
2010-06-15 22:40
zgxyz2008
Rank: 4
等 级:业余侠客
帖 子:67
专家分:202
注 册:2008-10-28
收藏
得分:0 
一处height变量打错了,还有个getheight函数没有定义,缺少一个Cylinder对象名....
2010-06-20 00:11
qq251168233
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-6-20
收藏
得分:0 
小弟借此领教!
2010-06-20 17:10
快速回复:教材上的例子,在C++6.0下总是编译不通过
数据加载中...
 
   



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

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