#include<iostream>
using namespace std;
const double Pi=3.14;
class ball
{protected:
int r;
public:
voidsetdata()
   {
	cout<<"please enter the r:"<<endl;
	cin>>r;
   }
intgetR()
   {
	return r;
   }
double volume()
   {
double v;
	 v=4/3*Pi*getR()*getR()*getR();
	return v;
   }
};
classyuan : public ball
{private:
int h;
public:
void input()
   {
	setdata();
	cout<<"please enter the h:"<<endl;
	cin>>h;
   }
double volume()
   {
double v;
	 v=Pi*getR()*getR()*h;
	return v;
   }
};
classzhui : public yuan
{public:
void input()
   {
	setdata();
   }
double volume()
   {
double v;
	 v=1/3*Pi*getR()*getR()*h;
	return v;
   }
private:

};
int main()
{
ball b;
b.setdata();
cout<<"the volume of ball is:"<<endl;
cout<<b.volume();
yuan y;
y.input();
cout<<"the volume of yuan is:"<<endl;
cout<<y.volume();
zhui z;
z.input();
cout<<"the volume of zhui is:"<<endl;
cout<<z.volume();
return 0;

}

//
E:\\jiue\jiejie.cpp(50) : error C2248: 'h' : cannot access private member declared in class 'yuan'
        E:\\jiue\jiejie.cpp(26) : see declaration of 'h'
执行 cl.exe 时出错.

jiue.exe - 1 error(s), 0 warning(s)