标题:在继承与派生中的类型问题
取消只看楼主
whl20888
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2008-9-3
 问题点数:0 回复次数:0 
在继承与派生中的类型问题
#include <iostream.h>
#include <math.h>
double pi=3.14;
class shape
{
 public:
      float x,y,z;
      double s;
      shape(float x1,float  y1,float z1)
      {
          x=x1;
          y=y1;
          z=z1;
      }
};
class  circle: public shape
{
public:
    circle(float x2,float y2,float z2):shape(x2,y2,z2)
    {}
    double getarea()
    {
        s=pi*z*z;
        return s;
    }
};
class rectangle : public shape
{
public:
    float p;
    rectangle(float x2,float y2,float z2):shape(x2,y2,z2)
    {  p=(x+y+z)/2;}
    float getarea()
    {   
        s=sqrt(p*(p-x)*(p-y)*(p-z));
        return s;
    }
};
/*class  squre: public rectangle
{   public:
    int i;
    squre(float x3,float y3,float z3):rectangle(x3,y3,z3){i=9;}
   
};*/
void main()
{
    circle  c1(1.12,2.1,3.5);
    rectangle  t1(3,4,5);
    
    
    cout<<t1.getarea()<<endl<<c1.getarea()<<endl;
}
为什么这样可以运行,但当去掉注释符号,老是说类型不对,这是怎么回事呢,高手解释下了!

[[it] 本帖最后由 whl20888 于 2008-12-13 22:36 编辑 [/it]]
搜索更多相关主题的帖子: 继承 派生 类型 
2008-12-13 22:17



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-249225-1-1.html




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

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