1:调用基类方法
#include<iostream>
using namespace std;
class Mammal
{
public:
void Move() const {cout<<"move one step"<<endl;}
void Move(int distance)//加cosnt和不加的区别
{
cout<<"move"<<distance<<"step"<<endl;
}
protected:
int itsAge;
int itsWight;
};
class Dog : public Mammal
{
public:
void Move() const;
};
void Dog::Move() const
{
cout <<"In dog move..."<<endl;
Mammal::Move(3);
}
int main()
{
Mammal bigAnimal;
Dog Fido;
bigAnimal.Move(10);
Fido.Mammal::Move(6);//覆盖基类后,仍可以通过限定方法名来调用它,在方法名前加基类名和两
// Fido.Move(12); //个冒号,baseClass::Method()
Fido.Move();
return 0;
}