私有继承、保护继承
#include<iostream>
using namespace std;
class Cylinder: private Circle
{public:
void SetHeight(int h){ height = h; }
int GetHeight( ){ return height; }
void ShowHeight( )
{ cout << "Derived class Cylinder: height = " << height << endl; }
void Set(int r, int h){ SetRadius(r); height = h; }
void Show( )
{ cout << "radius = " << GetRadius( ) << endl;
cout << "height = " << height << endl;
}
private:
int height;
};
int main()
{
obj.SetHeight(20);
obj.ShowHeight( );
obj.Set(30, 40);
obj.Show( );
return 0;
}
#include<iostream>
using namespace std;
class Cylinder: protected Circle
{public:
void SetHeight(int h){ height = h; }
int GetHeight( ){ return height; }
void ShowHeight( )
{ cout << "Derived class Cylinder: height = " << height << endl; }
void Set(int r, int h){ SetRadius(r); height = h; }
void Show( )
{ cout << "radius = " << GetRadius( ) << endl;
cout << "height = "<<height << endl;
}
private:
int height;
};
int main()
{
obj.SetHeight(20);
obj.ShowHeight( );
obj.Set(30, 40);
obj.Show( );
return 0;
}
#include<iostream>
using namespace std;
class Cylinder: private Circle
{public:
void SetHeight(int h){ height = h; }
int GetHeight( ){ return height; }
void ShowHeight( )
{ cout << "Derived class Cylinder: height = " << height << endl; }
void Set(int r, int h){ SetRadius(r); height = h; }
void Show( )
{ cout << "radius = " << GetRadius( ) << endl;
cout << "height = " << height << endl;
}
private:
int height;
};
int main()
{
obj.SetHeight(20);
obj.ShowHeight( );
obj.Set(30, 40);
obj.Show( );
return 0;
}
#include<iostream>
using namespace std;
class Cylinder: protected Circle
{public:
void SetHeight(int h){ height = h; }
int GetHeight( ){ return height; }
void ShowHeight( )
{ cout << "Derived class Cylinder: height = " << height << endl; }
void Set(int r, int h){ SetRadius(r); height = h; }
void Show( )
{ cout << "radius = " << GetRadius( ) << endl;
cout << "height = "<<height << endl;
}
private:
int height;
};
int main()
{
obj.SetHeight(20);
obj.ShowHeight( );
obj.Set(30, 40);
obj.Show( );
return 0;
}