[求助]有关派生类的
#include<iostream>using namespace std;
const float PI=(float)3.14159;
class Shape
{
public:
Shape(int a){sh=a;}
private:
int sh;
};
class Rectangle:public Shape
{
public:
Rectangle(float wid,float len,int b):Shape(b){width=wid;lenth=len;}
float GetArea();
void display();
private:
float width;
float lenth;
};
float Rectangle::GetArea()
{
return width*lenth;
}
void Rectangle::display()
{
cout<<"Its area is: "<<GetArea()<<endl;
}
class Circle:public Shape
{
public:
Circle(float r=0.0,int c):Shape(c){radius=r;}//在编译时显示 : error C2548: 'Circle::Circle' : missing default parameter for parameter 2
void display();
float GetArea();
private:
float radius;
};
float Circle::GetArea()
{
return PI*radius*radius;
}
void Circle::display()
{
cout<<"Its area is: "<<GetArea()<<endl;
}
class Square:public Rectangle
{
public:
Square(float a=0.0,float b=0.0){a=wid;b=len;}
private:
float wid;
float len;
};
void main()
{
Circle A(3.0,2);
A.display();
Rectangle R(2.0,3.0,2);
}
我已经在类Circle中为Shape类传递了参数,但为啥还显示错误呢??
我不太明白,麻烦哪位看一下。
谢谢!!!