sách gpt4 ăn đã đi

clang - Swift: Khai báo 'mô tả' không thể ghi đè nhiều khai báo siêu lớp

In lại 作者:IT王子 更新时间:2023-10-29 05:35:40 30 4
mua khóa gpt4 giày nike

我有一个类似于下面的继承结构。我正在采用 Printable 协议(protocol)并努力覆盖 description 属性。我遇到了一个谷歌此时似乎不知道的奇怪错误,提示为第三类,并引用了第二类和第一类。

雪上加霜的是,下面的代码实际上编译得很好,但我的完整代码却没有。注释掉 Second 和 Third 的属性解决了问题,代码编译,测试通过等。

Swift 继承章节对此提供了指示。

有谁知道这是什么意思,什么情况会触发它?

/Users/ivanhoe/Dropbox/swift/convergence/Processable.swift:124:18: error: declaration 'description' cannot override more than one superclass declaration override var description : String { ^ /Users/ivanhoe/Dropbox/swift/convergence/Processable.swift:85:18: note: overridden declaration is here override var description : String { ^ /Users/ivanhoe/Dropbox/swift/convergence/Processable.swift:28:18: note: overridden declaration is here override var description : String {

import Foundation

class First : NSObject, Printable {

override var description : String {
return "first"
}
}

class Second : First {

override var description : String {
return "second"
}

}

class Third : Second {

override var description : String {
return "third"
}

}

println(Third())

câu trả lời hay nhất

和我一样的问题,解决了:

func customDescription() -> String {
trở lại ""
}

override var description: String {
return customDescription()
}

因此您可以根据需要多次重写函数

关于clang - Swift:声明 'description' 不能覆盖多个父类(super class)声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24459441/

30 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress