Python:
class Person:
def eat(self):
print("Person.eat")
class Author(Person):
def eat(self):
print("Author.eat")
class Programmer(Person):
def eat(self):
print("Programmer.eat")
class ProgrammerAuthor(Programmer,Author):
def test():
print("test")
#def eat(self):
# print("ProgrammerAuthor.eat")
#Python the priority of multi inherit: current class > the sequence of declared super class
programmerAuthor = ProgrammerAuthor()
programmerAuthor.eat()
没有任何问题
而C++编译阶段就会报二义性的错误
#include "stdafx.h"
class Person
{
public:
void eat()
{
printf("BaseClass.eat");
}
};
class Author : public Person
{
public:
void eat()
{
printf("Author.eat");
}
};
class Programmer : public Person
{
public:
void eat()
{
printf("Programmer.eat");
}
};
class DerivedClass : public Author,Programmer
{
public:
void eat()
{
printf("DerivedClass.eat");
}
};
int wmian()
{
Person person = DerivedClass();
}
error: base class "Person" is ambiguous