重写swift函数

重写swift函数,swift,overriding,Swift,Overriding,以下是我的游乐场(Xcode 7.3.1)的副本: C2和C3类覆盖C1类功能。D2类和D3类重写D1类函数。类Dx与类Cx的区别在于函数不返回任何内容 将此代码复制并传递到您的操场中。您应该在C2和C3类中得到一个错误: Playground execution failed: MyPlayground.playground:8:19: error: declaration 'z' cannot override more than one superclass declaration

以下是我的游乐场(Xcode 7.3.1)的副本:

C2和C3类覆盖C1类功能。D2类和D3类重写D1类函数。类Dx与类Cx的区别在于函数不返回任何内容

将此代码复制并传递到您的操场中。您应该在C2和C3类中得到一个错误:

Playground execution failed: MyPlayground.playground:8:19: error: declaration 'z' cannot override more than one superclass declaration
    override func z ( a: A ) -> C2 { return C2 () }
如果类B不是从类A继承的,那么就可以了。更改类B定义不会影响类Dx:对它们来说总是好的

我真的认为“斯威夫特王国有些东西烂了”。在Java中做同样的事情不是问题


你能解释一下我做错了什么吗?非常感谢。

注意到,只有当B是A的子类时才会发生这种情况。如果寻找真相,我相信您可以尝试将其发布到swift source github:)看起来您正在尝试两次覆盖相同的方法,使用不同的场景…非常感谢Denis。事实上,使用一种没有真正规范且仍在开发中的编程语言——Swift——是不好的:我指的是一种你不能依赖的语言和编译器。我会尝试向苹果公司报告这个问题,如果我得到解决,我会告诉你。。。
Playground execution failed: MyPlayground.playground:8:19: error: declaration 'z' cannot override more than one superclass declaration
    override func z ( a: A ) -> C2 { return C2 () }