这是代码:
class CommonField {
init(name: String) {}
}
class Base {
class Field: CommonField {}
}
class Derived: Base {
class Field: CommonField {}
}
let a = CommonField(name: "field") // works fine
let b = Base.Field(name: "base.field") // works fine
let c = Derived.Field(name: "derived.field") // error!
这是错误:
error: ambiguous use of 'init(name:)'
let c = Derived.Field(name: "derived.field")
^
note: found this candidate
class Field: CommonField {}
^
note: found this candidate
class Field: CommonField {}
^
我正在使用以下版本的swift编译器:
Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1)
Target: x86_64-apple-darwin18.2.0