#include<iostream>
using namespace std;
class Base1{
public:
void diaplay() const{
cout<<"enter Base1::display"<<endl;
}
};
class Base2:public Base1{
public:
void diaplay() const{ cout<<"enter Base2::display"<<endl;}
};
class Base3:public Base2{
public:
void diaplay() const{cout<<"enter Base3::display"<<endl;}
};
void fun(Base1 *str){
str->diaplay();
}
int main(){
Base1 bb1;
Base2 bb2;
Base3 bb3;
fun(&bb1);
fun(&bb2);
fun(&bb3);
return 0;
}
类型兼容规则是指在需要类型规则的任何地方,都可以使用公有派生类的对象来替代。在替代之后,派生类对象可以作为基类的对象使用,但只能使用从基类继承的成员。