标题:[求助]关于虚函数的内容
取消只看楼主
静思
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



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




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

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