| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 523 人关注过本帖
标题:[求助]关于虚函数的内容
取消只看楼主 加入收藏
静思
Rank: 3Rank: 3
来 自:沈阳
等 级:新手上路
威 望:8
帖 子:630
专家分:0
注 册:2006-2-28
收藏
 问题点数:0 回复次数:0 
[求助]关于虚函数的内容
#include<iostream>
using namespace std;
const float PI=(float)3.1416
class Shape()
{
public:
Shape();
~Shape();
virtual float GetArea(){return 0;}
};
class Rectangle:public Shape
{
public:
Rectangle(int wid,int len):width(wid),lenth(len){}
~Rectangle(){}
float GetArea(){return width*lenth;}
private:
float width;
float lenth;
};
class Circle:public Shape
{
public:
Circle(float r):raduis(r){}
~Circle(){}
float GetArea(){return PI*raduis*raduis;}
private:
float raduis;
};
class Square:public Rectangle
{
public:
Square(float len):Rectangle(len,len){}
~Square(){}
};
void main()
{
Shape *ptr;
ptr=new Rectangle(5,9);
cout<<"The area of the Rectangle is "<<ptr->GetArea()<<endl;
delete ptr;
ptr=new Circle(5);
cout<<"The area of the Circle is "<<ptr->GetArea()<<endl;
delete ptr;
ptr=new Square(6);
cout<<"The area of the Square is "<<ptr->GetArea()<<endl;
delete ptr;
}
有哪位看一下,里面的错误查不出来....




搜索更多相关主题的帖子: 函数 
2006-05-01 00:40
快速回复:[求助]关于虚函数的内容
数据加载中...
 
   



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

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