| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 357 人关注过本帖
标题:C++求救
只看楼主 加入收藏
cryboy
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-6-20
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
C++求救
下面这个程序为什么是错的?怎么错了,要怎么改呢?谢谢大家了。
#include<iostream>
using namespace std;
class Shape
{
public:
virtual float printArea() const=0;
};
class Circle:public Shape
{
    public:
Circle(float a):r(a){}
virtual float printArea()const
{cout<<"Circle'area:"<<3.1514*r*r<<endl;}
protected:
float r;
};
class Rectangle:public Shape
{
    public:
Rectangle(float a,float b):w(a),l(b){}
virtual float printArea()const
{cout<<"Rectangle'area:"<<w*l<<endl;}
protected:
float w;
float l;
};
class Triangle:public Shape
{
    public:
Triangle(float a,float b):w(a),h(b){}
virtual float printArea()const
{cout<<"Triangle'area:"<<0.5*w*h<<endl;}
protected:
float w;
float h;
};
int main()
{
Circle c(8);
Rectangle r(5,8);
Triangle t(2.6,6);
Shape*p=&c;
p->printArea();
Shape*p=&r;
p->printArea();
Shape*p=&t;
p->printArea();
return 0;
}
搜索更多相关主题的帖子: include public 
2010-06-20 17:30
智若愚
Rank: 2
等 级:论坛游民
帖 子:2
专家分:10
注 册:2010-6-9
收藏
得分:10 
编译一下,说你的p指针,重复定义,把后面的两个p换成别的字母,比如q 跟 pp啥的,还有你的每个类里的虚函数,都是float类型的,应该有返回值的啊!你在改改呗~~
2010-06-20 20:39
南国利剑
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:29
帖 子:1165
专家分:3536
注 册:2010-4-12
收藏
得分:10 
按二楼的意思先改改。

南国利剑
2010-06-20 22:05
快速回复:C++求救
数据加载中...
 
   



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

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