//Ex6_20.cpp
#include "iostream" 
using namespace std;
class Circle 
{private: 
   double x,y,r; 
 public: 
   void show() 
   {cout<<"O("<<x<<","<<y<<")"<<" R-"<<r<<endl;} 
   Circle(double x1,double y1,double r1) 
   {x=x1;y=y1;r=r1;} 
   double getr() 
   {return r;} 
   virtual double volume() 
   {return(0);} 
}; 
class Cylinder:public Circle 
{private: 
    double h; 
 public: 
   void show() 
   {Circle::show(); 
    cout<<"H-"<<h<<endl;} 
   Cylinder(double x1,double y1,double r1,double h1):Circle(x1,y1,r1) 
   {h=h1;} 
   virtual double volume()  //此处可以不显式地声明虚函数 
   {double R=getr(); 
    return(3.14*R*R*h);} 
}; 
void f(Circle &p)   //基类对象的引用做参数 
{cout<<"V="<<p.volume()<<endl;} 
void main() 
{Cylinder p(0,1,3,5); 
 p.show(); 
 f(p);    //派生类对象做实参 
}
