求救
程序如下:#include<iostream.h>
class Shape
{public:
virtual float area()const{return 0.0;}
virtual float volume()const{return 0.0;}
virtual void shapeName()const=0; //纯虚函数//
};
//shapeName函数与派生类密切相关,应当在派生类中定义
//由于Point类中不再对area和volume函数重新定义,因此没有声明为纯虚函数
class Point:public Shape
{
public:
Point(float,float);
void setPoint(float,float);
float getX()const {return x;}
float getY()const {return y;}
virtual void shapeName()const{cout<<"Point:";}//对虚函数进行再定义
protected:
float x,y;
};
Point::Point(float a,float b)
{
x=a;
y=b;
}
void Point::setPoint(float a,float b)
{
x=a;
y=b;
}
//由于点是没有面积和体积的,因此不必重新定义area和volume
class Circle:public Point
{
public:
Circle(float a,float b,float r):Point(a,b),radius(r){}
void setRadius(float r) {radius=r;}
float getRadius()const;
virtual float area()const;
virtual void shapeName()const{cout<<"Circle:";} //对虚函数进行再定义//
protected:
float radius;
};
float Circle::getRadius()const {return radius;}
float Circle::area()const {return 3.14*radius*radius;}//重新定义area函数
class Cylinder:public Circle
{
public:
Cylinder(float a=0,float b=0,float r=0,float h=0);
void setHeight(float);
virtual float area()const;
virtual float volume()const;
virtual void shapeName()const{cout<<"Cylinder: ";} //对虚函数进行再定义//
protected:
float height;
};
Cylinder::Cylinder(float a,float b,float r,float h):Circle(a,b,r),height(h){}
void Cylinder::setHeight(float h){height=h;}
float Cylinder::area()const
{
return 2*Circle::area()+2*3.14*radius*height;
}
float Cylinder::volume()const
{
return Circle::area()*height;
}
void main()
{Point point(3.2,4.5);
Circle circle(2.4,1.2,5.6);
Cylinder cylinder(3.5,6.4,5.2,10.5);
point.shapeName();
cout<<point.x<<point.y<<endl;
}
错误出在倒数第二行,为什么会出错呢?错出在什么地方了, 另外cout<<point.setPoint()<<endl;为什么也不行呢?请好心人帮忙解答一下 详尽一些 谢谢了