我有两门课,形状和正方形
class Shape {
var numberOfSides = 0
var name: String
init(name:String) {
self.name = name
}
func simpleDescription() -> String {
return "A shape with \(numberOfSides) sides."
}
}
class Square: Shape {
var sideLength: Double
init(sideLength:Double, name:String) {
super.init(name:name) // Error here
self.sideLength = sideLength
numberOfSides = 4
}
func area () -> Double {
return sideLength * sideLength
}
}
通过上面的实现,我得到了错误:
property 'self.sideLength' not initialized at super.init call
super.init(name:name)
为什么我要设置self。调用super.init之前的sidelth ?