尝试在多重继承中调用超类的构造函数时出错。幕后发生了什么?

问题描述 投票:0回答:1
class A:
    def __init__(self):
        print("Reporting from A")

    def feature1(self):
        return "feature1 from A working!"

class B(A):
    def __init__(self):
        print("Reporting from B")

    def feature2(self):
        return  "feature2 from B working!"

class C(A,B):                               # multiple inheritance
    def __init__(self):
        super().__init__()
        print("Reporting from C")

    def feature3(self):
        return  "feature3 from C working!"


c = C()

错误消息:

class C(A,B):                               # multiple inheritance

TypeError: Cannot create a consistent method resolution
order (MRO) for bases A, B

但是当我将继承顺序从(A,B)更改为(B,A)时,它可以正常工作。**

python python-3.x multiple-inheritance
1个回答
-1
投票

结果,对于类似问题已经有了很好的解释:

TypeError: Cannot create a consistent method resolution order (MRO)

© www.soinside.com 2019 - 2024. All rights reserved.