#include<iostream>
using namespace std;
class Base
{
public:
void Print(string str)
{
cout<<"Base"<<str<<endl;
}
};
class Derive1:public Base
{
public:
void Print(string str)
{
cout<<"Derive1"<<str<<endl;
}
};
class Derive2:public Derive1
{
public:
void Print(string str)
{
cout<<"Derive2"<<str<<endl;
}
};
int main(void)
{
Base ob1 ;
ob1.Print("::Print()");
Derive1 ob2 ;
ob2.Print("::Print()");
Derive2 ob3 ;
ob3.PrintPrint("::Print()");
return 0 ;
}
结果是:
Base::Print()
Derive1::Print()
Derive2::Print()
为什么 ob2 和 ob3 在调用Print函数的时候不会有二义性?? , 为什么它会正确的调用自己定义的Print函数???,而不是其它的,其原理是什么??