隐藏基类的方法与调用

2014-11-24 08:58:25 · 作者: · 浏览: 0
[cpp]
#include
using namespace std;

class mam{
public:
void move() const {cout << "mammal move one step.\n"; }
void move(int distance)const {
cout << "mommal move";
cout <<" " << distance << " " <<"steps." << endl;
}
protected:
int age;
int weight;
};

class dog:public mam {
public:
void move()const { cout << "dog move 5 steps. " << endl; }
};

int main()
{
mam animal;
dog fido;
animal.move();
animal.move(2);
fido.move();
fido.mam::move(10); //调用基类的方法。
return 0;
}