| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 809 人关注过本帖
标题:有哪个高手可以帮我看看这个程序哪里有问题吗?谢谢
只看楼主 加入收藏
chuxuechengxu
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-6-18
收藏
 问题点数:0 回复次数:3 
有哪个高手可以帮我看看这个程序哪里有问题吗?谢谢
#include<iostream>
using namespace std;
class shape
{
public:
    shape(){}
    ~shape(){}
    virtual float GetArea(){return -1;}
};
class Rectangle:public shape
{
public:
    Rectangle(int len,int wid){};
    ~Rectangle(){};
    virtual float GetArea(){return len*wid;}
private:
    int wid;
    int len;
};
void main()
{
    shape *sp;
    sp = new Rectangle(2,3);
    cout<<"the area of the rectangle is"<<sp->GetArea()<<endl;
delete sp;
}
搜索更多相关主题的帖子: Rectangle shape int 
2008-06-18 08:42
zjl138
Rank: 1
等 级:新手上路
威 望:1
帖 子:788
专家分:0
注 册:2007-11-12
收藏
得分:0 
Rectangle(int len,int wid){};//这里没有对类的数据成员赋值.

virtual float GetArea(){return len*wid;}//这里的virtual最好也去掉吧.

[quote]/*****************************************************************
** HighlightCodeV3.0 software by yzfy(雨中飞燕) http:// **
*****************************************************************/
#include<iostream>
using namespace std;
class shape
{
public:
    shape(){}
   
~shape(){}
   
virtual float GetArea(){return -1;}
}
;
class Rectangle:public shape
{
public:
    Rectangle(int l,int w){len=l;wid=w;};
    ~Rectangle(){};
    float GetArea(){return len*wid;}
private:
    int wid;
    int len;
};
int main()
{
   
shape *sp;
    sp = new Rectangle(2,3);
    cout<<"the area of the rectangle is"<<sp->GetArea()<<endl;
    delete sp;
    return 0;
}

[\quote]

i like linux...
2008-06-18 10:36
mqh21364
Rank: 1
等 级:新手上路
帖 子:642
专家分:0
注 册:2008-2-28
收藏
得分:0 
楼上说的对,你没有有两个参数的构造函数啊 。

前不见古人,后不见来者。念天地之悠悠,独怆然而涕下。
2008-06-18 11:00
chuxuechengxu
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-6-18
收藏
得分:0 
恩,谢谢
2008-06-25 17:00
快速回复:有哪个高手可以帮我看看这个程序哪里有问题吗?谢谢
数据加载中...
 
   



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

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