/*派生类成员函数与基类成员函数同名*/
#include <iostream>
using namespace std;
class Circle
{public:
void Set(int r){ radius = r; }
void Show( ){ cout << "Base class Circle: radius = " << radius << endl; }
private:
int radius;
};
class Cylinder: public Circle
{public:
void Set(int r, int h)
{ Base::Set(r);
height = h; }
void Show( )
{ Base::Show( );
cout << "Derived class Cylinder: height = " << height << endl;
}
private:
int height;
};
int main( )
{ Cylinder obj;
obj.Set(10, 20);
obj.Show( );
obj.Circle::Set(30);
obj. Circle::Show( );
return 0;
}
#include <iostream>
using namespace std;
class Circle
{public:
void Set(int r){ radius = r; }
void Show( ){ cout << "Base class Circle: radius = " << radius << endl; }
private:
int radius;
};
class Cylinder: public Circle
{public:
void Set(int r, int h)
{ Base::Set(r);
height = h; }
void Show( )
{ Base::Show( );
cout << "Derived class Cylinder: height = " << height << endl;
}
private:
int height;
};
int main( )
{ Cylinder obj;
obj.Set(10, 20);
obj.Show( );
obj.Circle::Set(30);
obj. Circle::Show( );
return 0;
}