我这个程序构造函数的参数怎么传不到基类去?
我这个程序主要功能是求,点point,圆circle,圆柱体cylinder的面积(表面积),不知道为什么在主函数中,通过cylinder的构造函数给这三个类的成员变量初始化,运行时圆柱的面积能算出来,但是圆的面积算不出来(得出的结果是0),半径的值就没给传过去,但是这个半径的值在算圆柱面积时传过去了呀,到底怎么回事啊?定义类的头文件:
#include <iostream.h>
const double PI=3.14;
class Point
{
protected:
int x,y;
public:
virtual void Area()
{
cout<<"Error: point have no area!"<<endl;
}
Point(int a=0,int b=0)
{
x=a;y=b;
cout<<"Point constructor:"<<x<<','<<y<<endl;
}
~Point(){
cout<<"Point destructor:"<<x<<','<<y<<endl;
}
};
class Circle:public Point
{
protected:
int radius;
double area1;
public:
void Area()
{
area1=PI*radius*radius;
cout<<"The circle's area is:"<<area1<<endl;
}
Circle(int a=0,int b=0,int r=0):Point(a,b)
{
radius=r;
cout<<"Circle constructor:"<<x<<','<<y<<','<<radius<<endl;
}
~Circle()
{
cout<<"Circle destructor:"<<x<<','<<y<<','<<radius<<endl;
}
};
class Cylinder:public Circle
{
protected:
int height;
double area2;
public:
void Area()
{
area2=2*PI*radius*radius+2*PI*radius*height;
cout<<"The cylinder's area is:"<<area2<<endl;
}
Cylinder(int a=0,int b=0,int r=0,int h=0):Circle(a,b,r)
{
height=h;
cout<<"Cylinder constructor:"<<x<<','<<y<<','<<radius<<','<<height<<endl;
}
~Cylinder()
{
cout<<"Cylinder destructor:"<<x<<','<<y<<','<<radius<<','<<height<<endl;
}
};
主函数:
#include "3 82.h"
void main()
{
Point point,*pa;
Circle circle;
Cylinder cylinder(1,2,3,4);
pa=&point;
pa->Area();
pa=&circle;
pa->Area();
pa=&cylinder;
pa->Area();
}
帮忙看一下什么原因造成的,谢谢!!!